Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AddUniqueSlugValidation update script breaks on linked fields #3856

Closed
bakerkretzmar opened this issue Jun 16, 2021 · 1 comment
Closed

AddUniqueSlugValidation update script breaks on linked fields #3856

bakerkretzmar opened this issue Jun 16, 2021 · 1 comment

Comments

@bakerkretzmar
Copy link

Bug Description

If a Blueprint's slug field is a linked field, e.g. a field defined in a common fieldset used in many places, the AddUniqueSlugValidation update script added in #3671 breaks.

Deep in the Blueprint class there's an array_merge() being called on the field key in the config, but on linked fields field is a string with the name of the original fieldset and field, so you get a TypeError: array_merge(): Argument #1 must be of type array, string given.

How to Reproduce

  1. Have a Statamic site on a version old enough to need to run that upgrade script, e.g. 3.1.18.
  2. Have a slug field in a fieldset.
  3. Have a Blueprint with that slug field linked, something like this:
      - handle: slug
        field: common.slug
        config:
          required: true
          localizable: true
  1. Run composer update and eventually get a TypeError.

Extra Detail

The error comes from line 470 of Statamic\Fields\Blueprint inside the ensureFieldInSectionHasConfig() method:

// Get existing field config.
$existingConfig = Arr::get($this->contents['sections'][$section]['fields'][$fieldKey], 'field', []);
// Merge in new field config.
$this->contents['sections'][$section]['fields'][$fieldKey]['field'] = array_merge($existingConfig, $config);
return $this->resetFieldsCache();

This method is being called from ensureFieldHasConfig() in the same class, which in turn is being called from the updateBlueprint() method in the AddUniqueSlugValidation update script.

In my case, the $existingConfig argument to array_merge() ends up being 'common.slug' which causes the error.

Environment

Statamic 3.1.23 Pro (3.1.18 before running the script)
Laravel 8.47.0
PHP 8.0.7
No addons installed

Install method (choose one):

  • Fresh install from statamic/statamic I think
@jasonvarga
Copy link
Member

Ah, thanks!

For what it's worth, it's not the end of the world if that doesn't run. If you do want slugs to be unique, you can manually add a unique_entry_value:{collection},{id},{site} validation rule. (Although from how detailed this issue is, I'm sure you worked that out.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants