Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / themes / contrib / bootstrap / src / Plugin / Alter / ThemeSuggestions.php
index ce29ba64bf6c19620e02428b7ba37e07a4910c4a..bf20a2307cdc977abb13a21c0c7377612413de30 100644 (file)
@@ -1,12 +1,7 @@
 <?php
-/**
- * @file
- * Contains \Drupal\bootstrap\Plugin\Alter\ThemeSuggestions.
- */
 
 namespace Drupal\bootstrap\Plugin\Alter;
 
-use Drupal\bootstrap\Annotation\BootstrapAlter;
 use Drupal\bootstrap\Bootstrap;
 use Drupal\bootstrap\Plugin\PluginBase;
 use Drupal\bootstrap\Utility\Unicode;
@@ -23,6 +18,8 @@ use Drupal\Core\Entity\EntityInterface;
 class ThemeSuggestions extends PluginBase implements AlterInterface {
 
   /**
+   * The element types that should be converted into Panel markup.
+   *
    * @var array
    */
   protected $bootstrapPanelTypes = ['details', 'fieldset'];
@@ -143,15 +140,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;
+      }
     }
   }
 
@@ -161,14 +161,14 @@ class ThemeSuggestions extends PluginBase implements AlterInterface {
    * This is a helper method because core's implementation of theme hook
    * suggestions on entities is inconsistent.
    *
-   * @see https://www.drupal.org/node/2808481
-   *
    * @param string $entity_type
    *   Optional. A specific type of entity to look for.
    * @param string $prefix
    *   Optional. A prefix (like "entity") to use. It will automatically be
    *   appended with the "__" separator.
    *
+   * @see https://www.drupal.org/node/2808481
+   *
    * @todo Remove/refactor once core issue is resolved.
    */
   protected function addSuggestionsForEntity($entity_type = 'entity', $prefix = '') {
@@ -180,6 +180,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 +198,11 @@ class ThemeSuggestions extends PluginBase implements AlterInterface {
           $suggestions[] = $prefix . $entity_type_id . '__' . $entity->bundle() . '__' . $view_mode;
         }
       }
+
+      // Add suggestions.
+      if ($suggestions) {
+        $this->addSuggestion($suggestions);
+      }
     }
   }
 
@@ -206,6 +213,7 @@ class ThemeSuggestions extends PluginBase implements AlterInterface {
    *   The theme hook suggestion to build.
    *
    * @return array
+   *   An list of theme hook suggestions.
    */
   protected function buildSuggestions($hook) {
     $suggestions = [];