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
- Have a Statamic site on a version old enough to need to run that upgrade script, e.g. 3.1.18.
- Have a
slug field in a fieldset.
- Have a Blueprint with that
slug field linked, something like this:
- handle: slug
field: common.slug
config:
required: true
localizable: true
- 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
Bug Description
If a Blueprint's
slugfield is a linked field, e.g. a field defined in acommonfieldset used in many places, theAddUniqueSlugValidationupdate script added in #3671 breaks.Deep in the
Blueprintclass there's anarray_merge()being called on thefieldkey in the config, but on linked fieldsfieldis 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
slugfield in a fieldset.slugfield linked, something like this:composer updateand eventually get a TypeError.Extra Detail
The error comes from line 470 of
Statamic\Fields\Blueprintinside theensureFieldInSectionHasConfig()method:cms/src/Fields/Blueprint.php
Lines 466 to 472 in 9aa7a52
This method is being called from
ensureFieldHasConfig()in the same class, which in turn is being called from theupdateBlueprint()method in theAddUniqueSlugValidationupdate script.In my case, the
$existingConfigargument toarray_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):
statamic/statamicI think