Skip to content

AddUniqueSlugValidation update script breaks on linked fields #3856

@bakerkretzmar

Description

@bakerkretzmar

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions