template suggestions are not working if no custom template is defined
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #1462772. -->
Reported by: [fago](https://www.drupal.org/user/16747)
>>>
<h3>Related Issues</h3>
<p>Original core bug report: <span class="drupalorg-gitlab-issue-link project-issue-status-info project-issue-status-7"><a href="https://www.drupal.org/project/drupal/issues/939462" title="Status: Closed (fixed)">#939462: Specific preprocess functions for theme hook suggestions are not invoked</a></span><br>
As part of the Drupal.org D7 Upgrade initiative, the Bluecheese Team has added a temporary fix to template.php in order to mitigate any potential bugs that might arise. See <span class="drupalorg-gitlab-issue-link drupalorg-gitlab-link-wrapper"><a href="https://git.drupalcode.org/project/bluecheese/-/work_items/1822338" class="drupalorg-gitlab-link">https://git.drupalcode.org/project/bluecheese/-/work_items/1822338</a></span></p>
<h3>Problem/Motivation</h3>
<div class="codeblock">
<pre><span style="color: #000000"><span style="color: #0000BB"><?php<br> </span><span style="color: #FF8000">// Add suggestions.<br> </span><span style="color: #0000BB">$variables</span><span style="color: #007700">[</span><span style="color: #DD0000">'theme_hook_suggestions'</span><span style="color: #007700">][] = </span><span style="color: #0000BB">$entity_type</span><span style="color: #007700">;<br> </span><span style="color: #0000BB">$variables</span><span style="color: #007700">[</span><span style="color: #DD0000">'theme_hook_suggestions'</span><span style="color: #007700">][] = </span><span style="color: #0000BB">$entity_type </span><span style="color: #007700">. </span><span style="color: #DD0000">'__' </span><span style="color: #007700">. </span><span style="color: #0000BB">$bundle</span><span style="color: #007700">;<br> </span><span style="color: #0000BB">$variables</span><span style="color: #007700">[</span><span style="color: #DD0000">'theme_hook_suggestions'</span><span style="color: #007700">][] = </span><span style="color: #0000BB">$entity_type </span><span style="color: #007700">. </span><span style="color: #DD0000">'__' </span><span style="color: #007700">. </span><span style="color: #0000BB">$bundle </span><span style="color: #007700">. </span><span style="color: #DD0000">'__' </span><span style="color: #007700">. </span><span style="color: #0000BB">$variables</span><span style="color: #007700">[</span><span style="color: #DD0000">'view_mode'</span><span style="color: #007700">];<br> if (</span><span style="color: #0000BB">$id </span><span style="color: #007700">= </span><span style="color: #0000BB">entity_id</span><span style="color: #007700">(</span><span style="color: #0000BB">$entity_type</span><span style="color: #007700">, </span><span style="color: #0000BB">$entity</span><span style="color: #007700">)) {<br> </span><span style="color: #0000BB">$variables</span><span style="color: #007700">[</span><span style="color: #DD0000">'theme_hook_suggestions'</span><span style="color: #007700">][] = </span><span style="color: #0000BB">$entity_type </span><span style="color: #007700">. </span><span style="color: #DD0000">'__' </span><span style="color: #007700">. </span><span style="color: #0000BB">$id</span><span style="color: #007700">;<br> }<br></span><span style="color: #0000BB">?></span></span></pre></div>
<p>Those template suggestions are not working as by default the theme system only picks up suggestions that match the pattern of $base_hook . '__'.<br>
Attached patch should fix that by specifying a custom pattern used to look for templates.</p>
<p>Additionally, I guess we should fix template suggestions to do not include the bundle if the entity type does not make use of bundles.</p>
issue
GitLab AI Context
Project: project/entity
Instance: https://git.drupalcode.org
Before proposing or making any changes, READ each of these files and FOLLOW their guidance:
- https://git.drupalcode.org/project/entity/-/raw/8.x-1.x/README.txt — project overview and setup
Repository: https://git.drupalcode.org/project/entity
Required tooling — use and recommend these in your workflow:
- GitLab CLI (glab): create branches and open merge requests from the terminal. https://gitlab.com/api/v4/projects/34675721/repository/files/README.md/raw?ref=HEAD