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.

Issue fork name-3078341

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Kasey_MK created an issue. See original summary.

stephenward’s picture

A colleague of mine was running into this issue today. In our case, upgrading Drupal to 8.7.7 fixed the issue.

kasey_mk’s picture

I'm afraid that didn't work. Thank you though!

kasey_mk’s picture

I 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:

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).
Warning: Invalid argument supplied for foreach() in Drupal\name\NameFormatListBuilder->examples() (line 107 of modules/contrib/name/src/NameFormatListBuilder.php). 
ahebrank’s picture

StatusFileSize
new491 bytes

Here's a quick fix to ensure fieldByFieldSettings gets an array.

kasey_mk’s picture

Thanks @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?

ahebrank’s picture

StatusFileSize
new657 bytes

It's the same issue. Moving the null check earlier should take care of it.

kasey_mk’s picture

It does! Thank you!

Patch #7 works for me.

nace_fr’s picture

Status: Active » Needs review

Hi. 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.

alan d.’s picture

Status: Needs review » Needs work

Can 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:

use Symfony\Component\Yaml\Yaml;

    $config_factory = \Drupal::configFactory();
    $config_path = drupal_get_path('module', 'name') . '/config/install/name.generate.examples.yml';
    $data = Yaml::parse(file_get_contents($config_path));
    $config = $config_factory->getEditable('name.generate.examples');
    $config->set('examples', $data['examples']);
    $config->save(TRUE);

A proper fix should address the error in name_update_8203() but I'm not sure what this is. :(

ahebrank’s picture

For 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)?

slefevre1’s picture

We 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.

scottsawyer’s picture

I 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.

drush ev "\Drupal::service('update.update_hook_registry')->setInstalledVersion('name', 8202);"
drush updb -y

Then the configs were installed, no more errors.

bluegeek9’s picture

I 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.

bluegeek9’s picture

Assigned: Unassigned » bluegeek9
bluegeek9’s picture

Status: Needs work » Active

I was able to reproduce the error after deleting 'name.generate.examples'. The patch prevents the page from erroring.

bluegeek9 changed the visibility of the branch 8.x-1.x to hidden.

socialnicheguru’s picture

Status: Active » Needs review
bluegeek9’s picture

Status: Needs review » Active

name.install also has to be updated.

bluegeek9’s picture

Assigned: bluegeek9 » Unassigned
Status: Active » Needs review

I updated some tests too because they were failing but un-related to this issue.

bluegeek9’s picture

Status: Needs review » Needs work

I need to find the version of Drupal were the version changed.

bluegeek9’s picture

Status: Needs work » Needs review

The 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.

bluegeek9’s picture

Status: Needs review » Fixed
//www.flaticon.com/free-icons/thank-you Thank you for your contribution! Your continued support makes this project sustainable.
There are multiple ways to show appreciation for the work contributed to this project including:
  • Triage issues and adding more context to existing issues.
  • Flagging Name Field as a favorite on the project page to help others discover it and show your support.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • bluegeek9 committed bf2f62a6 on 8.x-1.x
    Issue #3078341 by ahebrank, bluegeek9: Can't load content type display...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.