Updated all the contrib modules to their latest versions.
[yaffs-website] / web / modules / contrib / metatag / src / MetatagDefaultsListBuilder.php
index 3811665f091b5a05a512b4de1af8bf74468844d0..0b4945009cf1504169edceb86e0509cbb8cbe870 100644 (file)
@@ -13,17 +13,42 @@ class MetatagDefaultsListBuilder extends ConfigEntityListBuilder {
   /**
    * {@inheritdoc}
    */
-  public function load() {
-    $entities = parent::load();
+  protected function getEntityIds() {
+    $query = $this->getStorage()->getQuery()
+      ->condition('id', 'global', '<>');
 
-    // Move the Global defaults to the top. Don't assume that the global config
-    // exists, it might have been removed.
-    if (isset($entities['global'])) {
-      return ['global' => $entities['global']] + $entities;
+    // Only add the pager if a limit is specified.
+    if ($this->limit) {
+      $query->pager($this->limit);
     }
-    else {
-      return $entities;
+
+    $entity_ids = $query->execute();
+
+    // Load global entity always.
+    return $entity_ids + $this->getParentIds($entity_ids);
+  }
+
+  /**
+   * Gets the parent entity ids for the list of entities to load.
+   *
+   * @param array $entity_ids
+   *   The metatag entity ids.
+   *
+   * @return array
+   *   The list of parents to load
+   */
+  protected function getParentIds(array $entity_ids) {
+    $parents = ['global' => 'global'];
+    foreach ($entity_ids as $entity_id) {
+      if (strpos($entity_id, '__') !== FALSE) {
+        $entity_id_array = explode('__', $entity_id);
+        $parent = reset($entity_id_array);
+        $parents[$parent] = $parent;
+      }
     }
+    $parents_query = $this->getStorage()->getQuery()
+      ->condition('id', $parents, 'IN');
+    return $parents_query->execute();
   }
 
   /**
@@ -64,7 +89,7 @@ class MetatagDefaultsListBuilder extends ConfigEntityListBuilder {
   /**
    * Renders the Metatag defaults label plus its configuration.
    *
-   * @param Drupal\Core\Entity\EntityInterface $entity
+   * @param \Drupal\Core\Entity\EntityInterface $entity
    *   The Metatag defaults entity.
    *
    * @return array