From 90bc697634068682acac5c4c2b6ddbdae60dfa39 Mon Sep 17 00:00:00 2001
From: Mark Carver <mark.carver@me.com>
Date: Tue, 13 Jun 2017 12:57:32 -0500
Subject: [PATCH] Issue #2885808 by markcarver:
 ThemeSuggestions::addSuggestionsForEntity doesn't work

---
 src/Plugin/Alter/ThemeSuggestions.php | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/src/Plugin/Alter/ThemeSuggestions.php b/src/Plugin/Alter/ThemeSuggestions.php
index ce29ba6..b4a4c63 100644
--- a/src/Plugin/Alter/ThemeSuggestions.php
+++ b/src/Plugin/Alter/ThemeSuggestions.php
@@ -143,15 +143,18 @@ class ThemeSuggestions extends PluginBase implements AlterInterface {
    ***************************************************************************/
 
   /**
-   * Add a suggestion to the list of suggestions.
+   * Adds suggestions based on an array of hooks.
    *
-   * @param string $hook
-   *   The theme hook suggestion to add.
+   * @param string|string[] $hook
+   *   A single theme hook suggestion or an array of theme hook suggestions.
    */
   protected function addSuggestion($hook) {
-    $suggestions = $this->buildSuggestions($hook);
-    foreach ($suggestions as $suggestion) {
-      $this->suggestions[] = $suggestion;
+    $hooks = (array) $hook;
+    foreach ($hooks as $hook) {
+      $suggestions = $this->buildSuggestions($hook);
+      foreach ($suggestions as $suggestion) {
+        $this->suggestions[] = $suggestion;
+      }
     }
   }
 
@@ -180,6 +183,8 @@ class ThemeSuggestions extends PluginBase implements AlterInterface {
     // Extract the entity.
     if ($entity = $this->getEntityObject($entity_type)) {
       $entity_type_id = $entity->getEntityTypeId();
+      $suggestions = [];
+
       // Only add the entity type identifier if there's a prefix.
       if (!empty($prefix)) {
         $prefix .= '__';
@@ -196,6 +201,11 @@ class ThemeSuggestions extends PluginBase implements AlterInterface {
           $suggestions[] = $prefix . $entity_type_id . '__' . $entity->bundle() . '__' . $view_mode;
         }
       }
+
+      // Add suggestions.
+      if ($suggestions) {
+        $this->addSuggestion($suggestions);
+      }
     }
   }
 
-- 
2.12.2

