diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 768213c..248c795 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -517,11 +517,8 @@ function _theme($hook, $variables = array()) { $base_theme_hook = $hook; } - // Entity based theme suggestions. - $suggestions = theme_get_entity_suggestions($variables, $base_theme_hook); - // Invoke hook_theme_suggestions_HOOK(). - $suggestions += $module_handler->invokeAll('theme_suggestions_' . $base_theme_hook, array($variables)); + $suggestions = $module_handler->invokeAll('theme_suggestions_' . $base_theme_hook, array($variables)); // If _theme() was invoked with a direct theme suggestion like // '#theme' => 'node__article', add it to the suggestions array before // invoking suggestion alter hooks. @@ -2247,33 +2244,6 @@ function theme_get_suggestions($args, $base, $delimiter = '__') { } /** - * Returns the entity based theme suggestions. - * - * @param $variables - * The theming variables. - * @param $entity_type_id - * The entity type id is being rendered. - * - * @return array - * An array of theme suggestions based on the entity type id. - */ -function theme_get_entity_suggestions($variables, $entity_type_id) { - $suggestions = array(); - $entity_definition = Drupal::entityManager()->getDefinition($entity_type_id, FALSE); - if ($entity_definition && $entity_definition->hasViewBuilderClass() && isset($variables['elements']['#view_mode'])) { - $entity = $variables['elements']["#$entity_type_id"]; - $sanitized_view_mode = strtr($variables['elements']['#view_mode'], '.', '_'); - - $suggestions[] = "{$entity->getEntityTypeId()}__$sanitized_view_mode";; - $suggestions[] = "{$entity->getEntityTypeId()}__{$entity->bundle()}"; - $suggestions[] = "{$entity->getEntityTypeId()}__{$entity->bundle()}__$sanitized_view_mode"; - $suggestions[] = "{$entity->getEntityTypeId()}__{$entity->id()}"; - $suggestions[] = "{$entity->getEntityTypeId()}__{$entity->id()}__$sanitized_view_mode"; - } - return $suggestions; -} - -/** * Prepare variables for maintenance page templates. * * Default template: maintenance-page.html.twig. diff --git a/core/modules/entity/entity.module b/core/modules/entity/entity.module index d3590a1..555f5b3 100644 --- a/core/modules/entity/entity.module +++ b/core/modules/entity/entity.module @@ -113,3 +113,20 @@ function entity_module_preuninstall($module) { } } } + +/** + * Implements hook_theme_suggestions_alter(). + */ +function entity_theme_suggestions_alter(array &$suggestions, array $variables, $hook) { + $entity_definition = Drupal::entityManager()->getDefinition($hook, FALSE); + if ($entity_definition && $entity_definition->hasViewBuilderClass() && isset($variables['elements']['#view_mode'])) { + $entity = $variables['elements']["#$hook"]; + $sanitized_view_mode = strtr($variables['elements']['#view_mode'], '.', '_'); + + $suggestions[] = "{$entity->getEntityTypeId()}__$sanitized_view_mode";; + $suggestions[] = "{$entity->getEntityTypeId()}__{$entity->bundle()}"; + $suggestions[] = "{$entity->getEntityTypeId()}__{$entity->bundle()}__$sanitized_view_mode"; + $suggestions[] = "{$entity->getEntityTypeId()}__{$entity->id()}"; + $suggestions[] = "{$entity->getEntityTypeId()}__{$entity->id()}__$sanitized_view_mode"; + } +} diff --git a/core/modules/node/src/Tests/NodeTemplateSuggestionsTest.php b/core/modules/node/src/Tests/NodeTemplateSuggestionsTest.php index 45d2b0c..5f413e4 100644 --- a/core/modules/node/src/Tests/NodeTemplateSuggestionsTest.php +++ b/core/modules/node/src/Tests/NodeTemplateSuggestionsTest.php @@ -26,7 +26,9 @@ function testNodeThemeHookSuggestions() { $build = \Drupal::entityManager()->getViewBuilder('node')->view($node, $view_mode); $variables['elements'] = $build; - $suggestions = theme_get_entity_suggestions($variables, 'node'); + $suggestions = array(); + $hook = 'node'; + \Drupal::moduleHandler()->alter('theme_suggestions', $suggestions, $variables, $hook); $this->assertEqual($suggestions, array('node__full', 'node__page', 'node__page__full', 'node__' . $node->id(), 'node__' . $node->id() . '__full'), 'Found expected node suggestions.'); @@ -35,7 +37,8 @@ function testNodeThemeHookSuggestions() { $build = \Drupal::entityManager()->getViewBuilder('node')->view($node, $view_mode); $variables['elements'] = $build; - $suggestions = theme_get_entity_suggestions($variables, 'node'); + $suggestions = array(); + \Drupal::moduleHandler()->alter('theme_suggestions', $suggestions, $variables, $hook); $this->assertEqual($suggestions, array('node__node_my_custom_view_mode', 'node__page', 'node__page__node_my_custom_view_mode', 'node__' . $node->id(), 'node__' . $node->id() . '__node_my_custom_view_mode'), 'Found expected node suggestions.'); }