When I have the name field enabled on a display for a content type, I can't get to the UI for managing that display. E.g., on /admin/structure/types/manage/CONTENTTYPE/display/DISPLAYNAME, I get the following error:
The website encountered an unexpected error. Please try again later.
TypeError: Argument 2 passed to Drupal\name\NameGenerator::filterByFieldSettings() must be of the type array, null given, called in modules/contrib/name/src/NameGenerator.php on line 162 in Drupal\name\NameGenerator->filterByFieldSettings() (line 211 of modules/contrib/name/src/NameGenerator.php).
My config for the field is this:
field_person_name:
weight: 0
label: inline
settings:
format: default
markup: none
output: default
list_format: ''
link_target: ''
preferred_field_reference: ''
preferred_field_reference_separator: ', '
alternative_field_reference: ''
alternative_field_reference_separator: ', '
third_party_settings: { }
type: name_default
region: content
On a display where the field is disabled, I can load the display edit page, but if I try to enable the field, the AJAX spinner by the "Name Formatter" dropdown just spins, and the field never enables.
Comments
Comment #2
stephenward commentedA colleague of mine was running into this issue today. In our case, upgrading Drupal to 8.7.7 fixed the issue.
Comment #3
kasey_mk commentedI'm afraid that didn't work. Thank you though!
Comment #4
kasey_mk commentedI wonder if the problem is related to the fact that no example names appear to be generated. On /admin/config/regional/name the "Examples" column is empty and these error messages appear:
Comment #5
ahebrank commentedHere's a quick fix to ensure fieldByFieldSettings gets an array.
Comment #6
kasey_mk commentedThanks @ahebrank - that does indeed let the page load.
I'm still seeing this error:
Warning: array_slice() expects parameter 1 to be array, null given in Drupal\name\NameGenerator->loadSampleValues() (line 158 of modules/contrib/name/src/NameGenerator.php).But maybe that's a separate issue?
Comment #7
ahebrank commentedIt's the same issue. Moving the null check earlier should take care of it.
Comment #8
kasey_mk commentedIt does! Thank you!
Patch #7 works for me.
Comment #9
nace_fr commentedHi. I have tried to reproduce this one, so I could test patch from #7, but with no success. Maybe it's because of the drupal version, since comment #2 mentions, it is working on 8.7.7.
I'll just change status to "Needs review" and maybe someone else could give it a try also.
Comment #10
alan d. commentedCan anyone see what has overridden config/install/name.generate.examples.yml for me please? [name.generate.examples - examples]
The source of the error is likely name_update_8203(), and any code based fix checking for a NULL value is only fixing a GIGO error, so this really should be fixed via an update script.
Blind update fix would be this:
A proper fix should address the error in name_update_8203() but I'm not sure what this is. :(
Comment #11
ahebrank commentedFor the site where I had the 500 error, the site reports having run the update despite the old name.examples.default still existing, so I'm guessing its config suffered a merge conflict around when the module updated. I tested the 8203 update hook using the console REPL and it worked fine.
I do think config should be assumed to be NULL until it's checked as a different type. It's probably overkill but maybe the module could attempt to reload the example config from the module config/install if it ever finds them to be blank in the site config (i.e., rerun 8203)?
Comment #12
slefevre1 commentedWe were getting this error on Drupal 8.8.6 just today . I applied patch #7 and that prevented the fatal error. We're still getting an error "Notice: Undefined index: in Drupal\name\Plugin\Field\FieldFormatter\NameFormatter->settingsSummary() (line 225 of modules/contrib/name/src/Plugin/Field/FieldFormatter/NameFormatter.php). ", but I can at least load the page now.
Comment #13
scottsawyerI just ran into this on a site that another developer installed this patch, which I removed as part of an upgrade. What I did to resolve it was set the registry installed version to 8202 and reran the database update.
Then the configs were installed, no more errors.
Comment #14
bluegeek9 commentedI think the problem is caused by the name.generate.examples being added after you installed the name module. This project only recently made a stable release, 8.x-1.0.
The update 8203, adds the name examples.
I am not sure why the update references 8.x-2.3, and the current version is 8.x-1.0.
I think name_update_8203 could be renamed to name_update_8101.
Comment #15
bluegeek9 commentedComment #16
bluegeek9 commentedI was able to reproduce the error after deleting 'name.generate.examples'. The patch prevents the page from erroring.
Comment #18
socialnicheguru commentedComment #19
bluegeek9 commentedname.install also has to be updated.
Comment #21
bluegeek9 commentedI updated some tests too because they were failing but un-related to this issue.
Comment #22
bluegeek9 commentedI need to find the version of Drupal were the version changed.
Comment #23
bluegeek9 commentedThe code was update to handle when name.generate.examples does not exist. Update function to add name.generate.examples if it is missing.
There were hook_update_N functions for versions that haven't been released. I removed and refactored the hook_update_N functions.
Comment #24
bluegeek9 commented