Skip to content
Snippets Groups Projects
Commit 5bf40faa 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
parent c8a07913
No related branches found
No related tags found
30 merge requests!8528Issue #3456871 by Tim Bozeman: Support NULL services,!8323Fix source code editing and in place front page site studio editing.,!6278Issue #3187770 by godotislate, smustgrave, catch, quietone: Views Rendered...,!3878Removed unused condition head title for views,!38582585169-10.1.x,!3818Issue #2140179: $entity->original gets stale between updates,!3742Issue #3328429: Create item list field formatter for displaying ordered and unordered lists,!3731Claro: role=button on status report items,!3668Resolve #3347842 "Deprecate the trusted",!3651Issue #3347736: Create new SDC component for Olivero (header-search),!3531Issue #3336994: StringFormatter always displays links to entity even if the user in context does not have access,!3355Issue #3209129: Scrolling problems when adding a block via layout builder,!3226Issue #2987537: Custom menu link entity type should not declare "bundle" entity key,!3154Fixes #2987987 - CSRF token validation broken on routes with optional parameters.,!3147Issue #3328457: Replace most substr($a, $i) where $i is negative with str_ends_with(),!3146Issue #3328456: Replace substr($a, 0, $i) with str_starts_with(),!3133core/modules/system/css/components/hidden.module.css,!2812Issue #3312049: [Followup] Fix Drupal.Commenting.FunctionComment.MissingReturnType returns for NULL,!2614Issue #2981326: Replace non-test usages of \Drupal::logger() with IoC injection,!2378Issue #2875033: Optimize joins and table selection in SQL entity query implementation,!2334Issue #3228209: Add hasRole() method to AccountInterface,!2062Issue #3246454: Add weekly granularity to views date sort,!1105Issue #3025039: New non translatable field on translatable content throws error,!1073issue #3191727: Focus states on mobile second level navigation items fixed,!877Issue #2708101: Default value for link text is not saved,!844Resolve #3036010 "Updaters",!617Issue #3043725: Provide a Entity Handler for user cancelation,!579Issue #2230909: Simple decimals fail to pass validation,!560Move callback classRemove outside of the loop,!555Issue #3202493
Pipeline #71623 passed with warnings
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';
}
}
......
  • catch @catch

    mentioned in commit 6e566f5d

    ·

    mentioned in commit 6e566f5d

    Toggle commit list
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment