Skip to content
Snippets Groups Projects
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
Branches
Tags
15 merge requests!8376Drupal views: adding more granularity to the ‘use ajax’ functionality,!8300Issue #3443586 View area displays even when parent view has no results.,!7567Issue #3153723 by quietone, Hardik_Patel_12: Change the scaffolding...,!7565Issue #3153723 by quietone, Hardik_Patel_12: Change the scaffolding...,!7509Change label "Block description" to "Block type",!7344Issue #3292350 by O'Briat, KlemenDEV, hswong3i, smustgrave, quietone: Update...,!6922Issue #3412959 by quietone, smustgrave, longwave: Fix 12 'un' words,!6848Issue #3417553 by longwave: Remove withConsecutive() in CacheCollectorTest,!6720Revert "Issue #3358581 by pfrenssen, _tarik_, a.dmitriiev, smustgrave:...,!6560Update ClaroPreRender.php, confirming classes provided are in array format,!6528Issue #3414261 by catch: Add authenticated user umami performance tests,!6501Issue #3263668 by omkar-pd, Wim Leers, hooroomoo: Re-enable inline form errors...,!6354Draft: Issue #3380392 by phma: Updating language weight from the overview reverts label if translated,!6324Issue #3416723 by Ludo.R: Provide a "node type" views default argument,!6119Issue #3405704 by Spokje, longwave: symfony/psr-http-message-bridge major version bump
Pipeline #71622 passed with warnings
Pipeline: drupal

#71640

    Pipeline: drupal

    #71635

      Pipeline: drupal

      #71628

        Showing with 20 additions and 12 deletions
        ......@@ -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';
        }
        ......
        ......@@ -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
        ......
        ......@@ -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';
        }
        }
        ......
        {# Output for Theme API test #}
        Original template for testing hook_theme_suggestions_alter().
        Hooks: {{ module_hook }} {{ theme_hook }}
        ......@@ -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],
        ......
        ......@@ -55,6 +55,7 @@ public function testTemplateSuggestions() {
        public function testGeneralSuggestionsAlter() {
        $this->drupalGet('theme-test/general-suggestion-alter');
        $this->assertSession()->pageTextContains('Original template for testing hook_theme_suggestions_alter().');
        $this->assertSession()->pageTextContains('Hooks: theme_test_theme none');
        // Install test_theme and test that themes can alter template suggestions.
        $this->config('system.theme')
        ......@@ -62,6 +63,7 @@ public function testGeneralSuggestionsAlter() {
        ->save();
        $this->drupalGet('theme-test/general-suggestion-alter');
        $this->assertSession()->pageTextContains('Template overridden based on new theme suggestion provided by the test_theme theme via hook_theme_suggestions_alter().');
        $this->assertSession()->pageTextContains('Hooks: theme_test_theme test_theme_theme_suggestions_alter');
        // Enable the theme_suggestions_test module to test modules implementing
        // suggestions alter hooks.
        ......@@ -69,6 +71,7 @@ public function testGeneralSuggestionsAlter() {
        $this->resetAll();
        $this->drupalGet('theme-test/general-suggestion-alter');
        $this->assertSession()->pageTextContains('Template overridden based on new theme suggestion provided by a module via hook_theme_suggestions_alter().');
        $this->assertSession()->pageTextContains('Hooks: theme_suggestions_test_theme_suggestions_alter test_theme_theme_suggestions_alter');
        }
        /**
        ......
        {# Output for Theme API test #}
        Template overridden based on new theme suggestion provided by a module via hook_theme_suggestions_alter().
        Hooks: {{ module_hook }} {{ theme_hook }}
        {# Output for Theme API test #}
        Template overridden based on new theme suggestion provided by the test_theme theme via hook_theme_suggestions_alter().
        Hooks: {{ module_hook }} {{ theme_hook }}
        ......@@ -45,7 +45,7 @@ function test_theme_theme_test_alter_alter(&$data) {
        /**
        * Implements hook_theme_suggestions_alter().
        */
        function test_theme_theme_suggestions_alter(array &$suggestions, array $variables, $hook) {
        function test_theme_theme_suggestions_alter(array &$suggestions, array &$variables, $hook) {
        \Drupal::messenger()->addStatus(__FUNCTION__ . '() executed.');
        // Theme alter hooks run after module alter hooks, so add this theme
        // suggestion to the beginning of the array so that the suggestion added by
        ......@@ -53,6 +53,7 @@ function test_theme_theme_suggestions_alter(array &$suggestions, array $variable
        // enabled.
        if ($hook == 'theme_test_general_suggestions') {
        array_unshift($suggestions, 'theme_test_general_suggestions__' . 'theme_override');
        $variables['theme_hook'] = 'test_theme_theme_suggestions_alter';
        }
        }
        ......
        0% Loading or .
        You are about to add 0 people to the discussion. Proceed with caution.
        Please register or to comment