Error in Taxonomy Term

Created on 3 February 2022, almost 3 years ago
Updated 30 October 2024, about 2 months ago

Hi,

I have error when choose "Use Inline Formatter Display" in Taxonomy Term Display:

Warning: Undefined array key "name" in template_preprocess_taxonomy_term() (line 128 of core/modules/taxonomy/taxonomy.module).
template_preprocess_taxonomy_term(Array, 'taxonomy_term', Array) (Line: 287)
Drupal\Core\Theme\ThemeManager->render('taxonomy_term', Array) (Line: 422)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 201)
Drupal\Core\Render\Renderer->render(Array) (Line: 463)

Works fine, only if added field "Field Formatter".

🐛 Bug report
Status

Fixed

Version

2.1

Component

Code

Created by

🇷🇺Russia antiden

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇦🇺Australia silverham

    I just wanted to mention, since this result shows up in internet search engines that if you experience the same error:

    `Warning: Undefined array key "name" in template_preprocess_taxonomy_term()`

    Then it could because one of your modules sets the `name` to be configurable in `manage display` but it is hidden. This is not a problem because an associated setting of `enable_base_field_custom_preprocess_skipping` per entity type should be set, then `name` processing is skipped but it is not set.

    Example code of what should be set:

    
    /**
     * Implements hook_entity_base_field_info_alter().
     *
     * NOTE: If title is hidden, then `enable_base_field_custom_preprocess_skipping`
     * must be set to true in hook_entity_type_build().
     */
    function MODULE_NAME_entity_base_field_info_alter(&$fields, $entity_type) {
      if ($entity_type->id() == 'taxonomy_term') {
        if (isset($fields['name'])) {
          $fields['name']->setDisplayConfigurable('view', TRUE);
        }
      }
    }
    
    /**
     * Implements hook_entity_type_build().
     *
     * If `enable_base_field_custom_preprocess_skipping` is set to true, then the
     * the name on the entity type e.g. taxonomy term's must be set to
     * `$fields['name']->setDisplayConfigurable('view', TRUE);` else name won't
     * show, if it's hidden.
     *
     * @see template_preprocess_taxonomy_term() in core taxonomy module.
     */
    function MODULE_NAME_entity_type_build(array &$entity_types) {
      if (isset($entity_types['taxonomy_term'])) {
        $entity_types['taxonomy_term']->set('enable_base_field_custom_preprocess_skipping', TRUE);
      }
    }
    

    @see also https://git.drupalcode.org/project/manage_display/-/blob/3.x/manage_disp...

Production build 0.71.5 2024