Commit 6e566f5d authored by catch's avatar catch
Browse files

Issue #3409982 by claudiu.cristea, longwave, alexpott, catch, Ghost of Drupal...

Issue #3409982 by claudiu.cristea, longwave, alexpott, catch, Ghost of Drupal Past: [D10.2 regression] Theme suggestions cannot alter variables anymore

(cherry picked from commit 5bf40faa)
parent ebdf86b4
Loading
Loading
Loading
Loading
Loading
+8 −8
Original line number Diff line number Diff line
@@ -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';
 *   }
@@ -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
@@ -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();
}
@@ -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';
  }
+1 −1
Original line number Diff line number Diff line
@@ -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
+2 −1
Original line number Diff line number Diff line
@@ -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';
  }
}

+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 }}
+1 −1
Original line number Diff line number Diff line
@@ -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