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.
*/
protected $entity;
+ /**
+ * The typed config manager.
+ *
+ * @var \Drupal\Core\Config\TypedConfigManagerInterface
+ */
+ protected $typedConfigManager;
+
/**
* {@inheritdoc}
*/
}
/**
- * 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)) {
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}
*/
* 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());
}
}