diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 3780d5e..dd10b0f 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -1035,13 +1035,25 @@ function theme($hook, $variables = array()) { 'theme_hook_original' => $original_hook, ); + // Set base hook for use with suggestions alter hooks. This way if e.g. + // '#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 + // hook as the last parameter to the suggestions alter hooks. + if (isset($info['base hook'])) { + $suggestions_base_hook = $info['base hook']; + } + else { + $suggestions_base_hook = $hook; + } + // Invoke theme hook suggestion alter hooks. $suggestions = array(); $suggestion_hooks = array( 'theme_suggestions', - 'theme_suggestions_' . $hook, + 'theme_suggestions_' . $suggestions_base_hook, ); - Drupal::moduleHandler()->alter($suggestion_hooks, $suggestions, $variables, $hook); + Drupal::moduleHandler()->alter($suggestion_hooks, $suggestions, $variables, $suggestions_base_hook); // Check if each suggestion exists in the theme registry, and if so, // use it instead of the hook that theme() was called with. For example, a @@ -1066,8 +1078,10 @@ function theme($hook, $variables = array()) { include_once DRUPAL_ROOT . '/' . $include_file; } } - // Add preprocess and process functions from the base hook to the $info - // array. + // Add preprocess functions from the base hook to the $info array. + // Previously we just replaced the entire $info array with $base_hook_info if + // any preprocess functions were set, but now we determine the suggestions + // first and then fire the appropriate preprocess functions. foreach (array('preprocess functions', 'process functions') as $processor) { if (isset($base_hook_info[$processor])) { $info[$processor] = $base_hook_info[$processor]; diff --git a/core/modules/field/field.module b/core/modules/field/field.module index 0adab64..4fe6e42 100644 --- a/core/modules/field/field.module +++ b/core/modules/field/field.module @@ -929,12 +929,10 @@ function field_page_build(&$page) { function field_theme_suggestions_field_alter(array &$suggestions, array $variables) { $element = $variables['element']; - $suggestions = array_merge($suggestions, array( - 'field__' . $element['#field_type'], - 'field__' . $element['#field_name'], - 'field__' . $element['#bundle'], - 'field__' . $element['#field_name'] . '__' . $element['#bundle'], - )); + $suggestions[] = 'field__' . $element['#field_type']; + $suggestions[] = 'field__' . $element['#field_name']; + $suggestions[] = 'field__' . $element['#bundle']; + $suggestions[] = 'field__' . $element['#field_name'] . '__' . $element['#bundle']; } /** diff --git a/core/modules/node/node.module b/core/modules/node/node.module index ffd6185..e5b4f24 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -672,10 +672,8 @@ function node_preprocess_block(&$variables) { function node_theme_suggestions_node_alter(array &$suggestions, array $variables) { $node = $variables['elements']['#node']; - $suggestions = array_merge($suggestions, array( - 'node__' . $node->bundle(), - 'node__' . $node->id(), - )); + $suggestions[] = 'node__' . $node->bundle(); + $suggestions[] = 'node__' . $node->id(); } /**