Template based on term bundle not working

Created on 26 April 2018, over 6 years ago
Updated 27 February 2023, over 1 year ago

Problem/Motivation

Two days ago we updated from 7.x-2.11 to 7.x-2.15 and noticed, that templates using the taxonomy term bundle in its name are not used anymore (i.e. "ds-3col-stacked-equal-width--taxonomy-term-industry.tpl.php" for terms of vocabulary "industry").
Digging through the code I found the following code (introduced in #2503653-23: Per node template suggestion ):

<?php
    if ($vars['elements']['#entity_type'] == 'taxonomy_term') {
      $entity_type = 'term';
    }

    // Get entity id and bundle
    $id = NULL;
    $bundle = $vars['elements']['#bundle'];
    $entity = isset($vars[$entity_type]) ? $vars[$entity_type] : (isset($vars['elements']['#' . $entity_type]) ? $vars['elements']['#' . $entity_type] : NULL);
    list($id,, $bundle) = entity_extract_ids($entity_type, $entity);
?>

Unfortunately there is no entity type named "term", so entity_extract_ids() returns NULL for $id and $bundle. Because of this the template suggestion based on the entity type and bundle are not built correctly and the (previously working) template is not used anymore.

Proposed resolution

Use $vars['elements']['#entity_type'] as parameter for entity_extract_ids().

Remaining tasks

🐛 Bug report
Status

RTBC

Version

2.0

Component

Code

Created by

🇩🇪Germany stborchert

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.

  • First commit to issue fork.
  • 🇮🇳India kunal_sahu Karnataka

    Hi , Tested the patch ds-fix_bundle_based_template_suggestions_for_terms-2966539-2.patch .

    Your patch applied cleanly

    PS C:\xampp\htdocs\drupal\web\themes\custom\ds-2966539> git apply -v .\ds-fix_bundle_based_template_suggestions_for_terms-2966539-2.patch
    Checking patch ds.module...
    Applied patch ds.module cleanly.

    RTBC ++.

    LGTM.

    Thanks
    Please merge.

  • @kunal_sahu opened merge request.
Production build 0.71.5 2024