- 🇺🇸United States Amber Himes Matz Portland, OR USA
Thanks for reporting this issue. We rely on issue reports like this one to resolve bugs and improve Drupal core. This issue is being triaged as part of the Bug Smash Initiative.
I don’t think you’re “magically” creating a new template suggestion by implementing
function MYMODULE_preprocess_node__event(&$variables) {}
. You’re implementing a hook that is covered by the core node module, which provides default template suggestions, including dynamic ones based on the machine name of the content type (aka “bundle”).See core/modules/node/node.module (“bundle” is the machine name of the content type):
/** * Implements hook_theme_suggestions_HOOK(). */ function node_theme_suggestions_node(array $variables) { $suggestions = []; $node = $variables['elements']['#node']; $sanitized_view_mode = strtr($variables['elements']['#view_mode'], '.', '_'); $suggestions[] = 'node__' . $sanitized_view_mode; $suggestions[] = 'node__' . $node->bundle(); $suggestions[] = 'node__' . $node->bundle() . '__' . $sanitized_view_mode; $suggestions[] = 'node__' . $node->id(); $suggestions[] = 'node__' . $node->id() . '__' . $sanitized_view_mode; return $suggestions; }
The way to create a new template suggestion, or to alter the suggestions provided by another module or theme, is to implement HOOK_theme_suggestions_alter() or HOOK_theme_suggestions_HOOK_alter(). You can use either of these hooks to add/remove suggestions from the list or reorder the list by making changes to the
$suggestions
array.I see a couple of problems with the original report that makes me think that maybe this is more of a misunderstanding of how the system is designed to work, rather than a bug with the system:
1) Implementing a specific hook for a template and then not creating that template seems counterproductive.
2) There is already a hook in Drupal’s API to reorder theme hook suggestions provided by any module or theme and that’shook_theme_suggestions_alter()
or it’s more specific counterpart,hook_theme_suggestions_HOOK_alter()
I could be totally wrong about this, so feel free to re-open and provide more information or context.