Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / web / core / lib / Drupal / Core / Entity / Plugin / DataType / ConfigEntityAdapter.php
index 093c77dd16b110db2f1f78c7852e155d87243002..55a8bba0b988e2216dfb97035248470865e8f94d 100644 (file)
@@ -2,7 +2,9 @@
 
 namespace Drupal\Core\Entity\Plugin\DataType;
 
+use Drupal\Core\Config\TypedConfigManagerInterface;
 use Drupal\Core\TypedData\Exception\MissingDataException;
+use Drupal\Core\TypedData\TypedDataManagerInterface;
 
 /**
  * Enhances EntityAdapter for config entities.
@@ -16,6 +18,13 @@ class ConfigEntityAdapter extends EntityAdapter {
    */
   protected $entity;
 
+  /**
+   * The typed config manager.
+   *
+   * @var \Drupal\Core\Config\TypedConfigManagerInterface
+   */
+  protected $typedConfigManager;
+
   /**
    * {@inheritdoc}
    */
@@ -68,10 +77,31 @@ class ConfigEntityAdapter extends EntityAdapter {
   }
 
   /**
-   * Gets the typed data manager.
+   * Gets the typed config manager.
    *
    * @return \Drupal\Core\Config\TypedConfigManagerInterface
-   *   The typed data manager.
+   *   The typed config manager.
+   */
+  protected function getTypedConfigManager() {
+    if (empty($this->typedConfigManager)) {
+      // Use the typed data manager if it is also the typed config manager.
+      // @todo Remove this in https://www.drupal.org/node/3011137.
+      $typed_data_manager = $this->getTypedDataManager();
+      if ($typed_data_manager instanceof TypedConfigManagerInterface) {
+        $this->typedConfigManager = $typed_data_manager;
+      }
+      else {
+        $this->typedConfigManager = \Drupal::service('config.typed');
+      }
+    }
+
+    return $this->typedConfigManager;
+  }
+
+  /**
+   * {@inheritdoc}
+   *
+   * @todo Remove this in https://www.drupal.org/node/3011137.
    */
   public function getTypedDataManager() {
     if (empty($this->typedDataManager)) {
@@ -81,6 +111,19 @@ class ConfigEntityAdapter extends EntityAdapter {
     return $this->typedDataManager;
   }
 
+  /**
+   * {@inheritdoc}
+   *
+   * @todo Remove this in https://www.drupal.org/node/3011137.
+   */
+  public function setTypedDataManager(TypedDataManagerInterface $typed_data_manager) {
+    $this->typedDataManager = $typed_data_manager;
+    if ($typed_data_manager instanceof TypedConfigManagerInterface) {
+      $this->typedConfigManager = $typed_data_manager;
+    }
+    return $this;
+  }
+
   /**
    * {@inheritdoc}
    */
@@ -97,7 +140,7 @@ class ConfigEntityAdapter extends EntityAdapter {
    *   The typed data.
    */
   protected function getConfigTypedData() {
-    return $this->getTypedDataManager()->createFromNameAndData($this->entity->getConfigDependencyName(), $this->entity->toArray());
+    return $this->getTypedConfigManager()->createFromNameAndData($this->entity->getConfigDependencyName(), $this->entity->toArray());
   }
 
 }