Loading core/lib/Drupal/Core/Render/theme.api.php +8 −8 Original line number Diff line number Diff line Loading @@ -687,7 +687,7 @@ function hook_theme_suggestions_HOOK(array $variables) { * node and taxonomy term templates based on the user being logged in. * * @code * function MYMODULE_theme_suggestions_alter(array &$suggestions, array $variables, $hook) { * function MYMODULE_theme_suggestions_alter(array &$suggestions, array &$variables, $hook) { * if (\Drupal::currentUser()->isAuthenticated() && in_array($hook, array('node', 'taxonomy_term'))) { * $suggestions[] = $hook . '__' . 'logged_in'; * } Loading @@ -699,8 +699,8 @@ function hook_theme_suggestions_HOOK(array $variables) { * An array of alternate, more specific names for template files, passed by * reference. * @param array $variables * An array of variables passed to the theme hook. Note that this hook is * invoked before any variable preprocessing. * An array of variables passed to the theme hook, passed by reference. Note * that this hook is invoked before any variable preprocessing. * @param string $hook * The base hook name. For example, if '#theme' => 'node__article' is called, * then $hook will be 'node', not 'node__article'. The specific hook called Loading @@ -709,7 +709,7 @@ function hook_theme_suggestions_HOOK(array $variables) { * * @see hook_theme_suggestions_HOOK_alter() */ function hook_theme_suggestions_alter(array &$suggestions, array $variables, $hook) { function hook_theme_suggestions_alter(array &$suggestions, array &$variables, $hook) { // Add an interface-language specific suggestion to all theme hooks. $suggestions[] = $hook . '__' . \Drupal::languageManager()->getCurrentLanguage()->getId(); } Loading Loading @@ -750,15 +750,15 @@ function hook_theme_suggestions_alter(array &$suggestions, array $variables, $ho * @endcode * * @param array $suggestions * An array of theme suggestions. * An array of theme suggestions, passed by reference. * @param array $variables * An array of variables passed to the theme hook. Note that this hook is * invoked before any preprocessing. * An array of variables passed to the theme hook, passed by reference. Note * that this hook is invoked before any preprocessing. * * @see hook_theme_suggestions_alter() * @see hook_theme_suggestions_HOOK() */ function hook_theme_suggestions_HOOK_alter(array &$suggestions, array $variables) { function hook_theme_suggestions_HOOK_alter(array &$suggestions, array &$variables) { if (empty($variables['header'])) { $suggestions[] = 'hookname__no_header'; } Loading core/lib/Drupal/Core/Theme/ThemeManager.php +1 −1 Original line number Diff line number Diff line Loading @@ -368,7 +368,7 @@ public function render($hook, array $variables) { * @internal * This method may change at any time. It is not for use outside this class. */ protected function buildThemeHookSuggestions(string $hook, string $info_base_hook, array $variables): array { protected function buildThemeHookSuggestions(string $hook, string $info_base_hook, array &$variables): array { // Set base hook for later use. For example if '#theme' => 'node__article' // is called, we run hook_theme_suggestions_node_alter() rather than // hook_theme_suggestions_node__article_alter(), and also pass in the base Loading core/modules/system/tests/modules/theme_suggestions_test/theme_suggestions_test.module +2 −1 Original line number Diff line number Diff line Loading @@ -8,10 +8,11 @@ /** * Implements hook_theme_suggestions_alter(). */ function theme_suggestions_test_theme_suggestions_alter(array &$suggestions, array $variables, $hook) { function theme_suggestions_test_theme_suggestions_alter(array &$suggestions, array &$variables, $hook) { \Drupal::messenger()->addStatus(__FUNCTION__ . '() executed.'); if ($hook == 'theme_test_general_suggestions') { $suggestions[] = $hook . '__module_override'; $variables['module_hook'] = 'theme_suggestions_test_theme_suggestions_alter'; } } Loading core/modules/system/tests/modules/theme_test/templates/theme-test-general-suggestions.html.twig +1 −0 Original line number Diff line number Diff line {# Output for Theme API test #} Original template for testing hook_theme_suggestions_alter(). Hooks: {{ module_hook }} {{ theme_hook }} core/modules/system/tests/modules/theme_test/theme_test.module +1 −1 Original line number Diff line number Diff line Loading @@ -32,7 +32,7 @@ function theme_test_theme($existing, $type, $theme, $path) { 'variables' => [], ]; $items['theme_test_general_suggestions'] = [ 'variables' => [], 'variables' => ['module_hook' => 'theme_test_theme', 'theme_hook' => 'none'], ]; $items['theme_test_foo'] = [ 'variables' => ['foo' => NULL], Loading Loading
core/lib/Drupal/Core/Render/theme.api.php +8 −8 Original line number Diff line number Diff line Loading @@ -687,7 +687,7 @@ function hook_theme_suggestions_HOOK(array $variables) { * node and taxonomy term templates based on the user being logged in. * * @code * function MYMODULE_theme_suggestions_alter(array &$suggestions, array $variables, $hook) { * function MYMODULE_theme_suggestions_alter(array &$suggestions, array &$variables, $hook) { * if (\Drupal::currentUser()->isAuthenticated() && in_array($hook, array('node', 'taxonomy_term'))) { * $suggestions[] = $hook . '__' . 'logged_in'; * } Loading @@ -699,8 +699,8 @@ function hook_theme_suggestions_HOOK(array $variables) { * An array of alternate, more specific names for template files, passed by * reference. * @param array $variables * An array of variables passed to the theme hook. Note that this hook is * invoked before any variable preprocessing. * An array of variables passed to the theme hook, passed by reference. Note * that this hook is invoked before any variable preprocessing. * @param string $hook * The base hook name. For example, if '#theme' => 'node__article' is called, * then $hook will be 'node', not 'node__article'. The specific hook called Loading @@ -709,7 +709,7 @@ function hook_theme_suggestions_HOOK(array $variables) { * * @see hook_theme_suggestions_HOOK_alter() */ function hook_theme_suggestions_alter(array &$suggestions, array $variables, $hook) { function hook_theme_suggestions_alter(array &$suggestions, array &$variables, $hook) { // Add an interface-language specific suggestion to all theme hooks. $suggestions[] = $hook . '__' . \Drupal::languageManager()->getCurrentLanguage()->getId(); } Loading Loading @@ -750,15 +750,15 @@ function hook_theme_suggestions_alter(array &$suggestions, array $variables, $ho * @endcode * * @param array $suggestions * An array of theme suggestions. * An array of theme suggestions, passed by reference. * @param array $variables * An array of variables passed to the theme hook. Note that this hook is * invoked before any preprocessing. * An array of variables passed to the theme hook, passed by reference. Note * that this hook is invoked before any preprocessing. * * @see hook_theme_suggestions_alter() * @see hook_theme_suggestions_HOOK() */ function hook_theme_suggestions_HOOK_alter(array &$suggestions, array $variables) { function hook_theme_suggestions_HOOK_alter(array &$suggestions, array &$variables) { if (empty($variables['header'])) { $suggestions[] = 'hookname__no_header'; } Loading
core/lib/Drupal/Core/Theme/ThemeManager.php +1 −1 Original line number Diff line number Diff line Loading @@ -368,7 +368,7 @@ public function render($hook, array $variables) { * @internal * This method may change at any time. It is not for use outside this class. */ protected function buildThemeHookSuggestions(string $hook, string $info_base_hook, array $variables): array { protected function buildThemeHookSuggestions(string $hook, string $info_base_hook, array &$variables): array { // Set base hook for later use. For example if '#theme' => 'node__article' // is called, we run hook_theme_suggestions_node_alter() rather than // hook_theme_suggestions_node__article_alter(), and also pass in the base Loading
core/modules/system/tests/modules/theme_suggestions_test/theme_suggestions_test.module +2 −1 Original line number Diff line number Diff line Loading @@ -8,10 +8,11 @@ /** * Implements hook_theme_suggestions_alter(). */ function theme_suggestions_test_theme_suggestions_alter(array &$suggestions, array $variables, $hook) { function theme_suggestions_test_theme_suggestions_alter(array &$suggestions, array &$variables, $hook) { \Drupal::messenger()->addStatus(__FUNCTION__ . '() executed.'); if ($hook == 'theme_test_general_suggestions') { $suggestions[] = $hook . '__module_override'; $variables['module_hook'] = 'theme_suggestions_test_theme_suggestions_alter'; } } Loading
core/modules/system/tests/modules/theme_test/templates/theme-test-general-suggestions.html.twig +1 −0 Original line number Diff line number Diff line {# Output for Theme API test #} Original template for testing hook_theme_suggestions_alter(). Hooks: {{ module_hook }} {{ theme_hook }}
core/modules/system/tests/modules/theme_test/theme_test.module +1 −1 Original line number Diff line number Diff line Loading @@ -32,7 +32,7 @@ function theme_test_theme($existing, $type, $theme, $path) { 'variables' => [], ]; $items['theme_test_general_suggestions'] = [ 'variables' => [], 'variables' => ['module_hook' => 'theme_test_theme', 'theme_hook' => 'none'], ]; $items['theme_test_foo'] = [ 'variables' => ['foo' => NULL], Loading