X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Flib%2FDrupal%2FCore%2FEntity%2FPlugin%2FDataType%2FConfigEntityAdapter.php;h=55a8bba0b988e2216dfb97035248470865e8f94d;hb=refs%2Fheads%2Fd864;hp=093c77dd16b110db2f1f78c7852e155d87243002;hpb=0bf8d09d2542548982e81a441b1f16e75873a04f;p=yaffs-website diff --git a/web/core/lib/Drupal/Core/Entity/Plugin/DataType/ConfigEntityAdapter.php b/web/core/lib/Drupal/Core/Entity/Plugin/DataType/ConfigEntityAdapter.php index 093c77dd1..55a8bba0b 100644 --- a/web/core/lib/Drupal/Core/Entity/Plugin/DataType/ConfigEntityAdapter.php +++ b/web/core/lib/Drupal/Core/Entity/Plugin/DataType/ConfigEntityAdapter.php @@ -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()); } }