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

Notice: Trying to access array offset on value of type null in field_config_label_instance() (line 436 of /var/www/html/docroot/core/modules/field/field.module) #5651

Closed
alanmels opened this issue Jun 15, 2022 · 2 comments

Comments

@alanmels
Copy link

alanmels commented Jun 15, 2022

Description of the bug

A single item configuration export page at admin/config/development/configuration/single/export is giving the notice in title.

Steps To Reproduce

To reproduce the behavior:

  1. Go to admin/config/development/logging and set All messages to display.
  2. Go to admin/config/development/configuration/single/export and see the reported notice.

Additional information

The offending line looks as $entity_label = $entity_type['label']; and the whole function as:

/**
 * Given a field array, display a unique label.
 */
function field_config_label_instance($instance, $config_name) {
  list($entity_type_name, $bundle, $field_name) = explode('.', str_replace('field.instance.', '', $config_name));
  $entity_type = entity_get_info($entity_type_name);
  $entity_label = $entity_type['label'];
  $bundle_label = isset($entity_type['bundles'][$bundle]['label']) ? $entity_type['bundles'][$bundle]['label'] : $bundle;
  return $entity_label . ' - ' . $bundle_label . ' - ' . $instance['label'];
}

Now, I've put the following check to find out which entity is causing the notice:

function field_config_label_instance($instance, $config_name) {
  list($entity_type_name, $bundle, $field_name) = explode('.', str_replace('field.instance.', '', $config_name));
  $entity_type = entity_get_info($entity_type_name);
  if (!isset($entity_type)) {
    sdpm($entity_type_name);
  }
  $entity_label = $entity_type['label'];
  $bundle_label = isset($entity_type['bundles'][$bundle]['label']) ? $entity_type['bundles'][$bundle]['label'] : $bundle;
  return $entity_label . ' - ' . $bundle_label . ' - ' . $instance['label'];
}

and it returned comment (which is not entity on Backdrop AFAIK) three times:

Screen Shot 2022-06-15 at 2 03 06 AM

Running the same check condition for $config_name has given:

field.instance.comment.comment_node_card.comment_body
  field.instance.comment.comment_node_page.comment_body
  field.instance.comment.comment_node_post.comment_body

I'm not sure what's the best solution here, but changing the code as below makes the notice go away:

function field_config_label_instance($instance, $config_name) {
  list($entity_type_name, $bundle, $field_name) = explode('.', str_replace('field.instance.', '', $config_name));
  $entity_type = entity_get_info($entity_type_name);
  if (isset($entity_type)) {
    $entity_label = $entity_type['label'];
    $bundle_label = isset($entity_type['bundles'][$bundle]['label']) ? $entity_type['bundles'][$bundle]['label'] : $bundle;
    return $entity_label . ' - ' . $bundle_label . ' - ' . $instance['label'];
  }
}

Should I create a PR or another solution preventing the comment configuration from being fed to the function should be considered?

@indigoxela
Copy link
Member

Possibly a duplicate of #5469

@alanmels
Copy link
Author

Well, turning on the Comment module made the notice go away, so it's definitely the same issue. Closing this one.

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

No branches or pull requests

2 participants