3 namespace Drupal\Core\Entity\Plugin\DataType;
5 use Drupal\Core\TypedData\Exception\MissingDataException;
8 * Enhances EntityAdapter for config entities.
10 class ConfigEntityAdapter extends EntityAdapter {
13 * The wrapped entity object.
15 * @var \Drupal\Core\Config\Entity\ConfigEntityInterface
22 public function get($property_name) {
23 if (!isset($this->entity)) {
24 throw new MissingDataException("Unable to get property $property_name as no entity has been provided.");
26 return $this->getConfigTypedData()->get($property_name);
32 public function set($property_name, $value, $notify = TRUE) {
33 if (!isset($this->entity)) {
34 throw new MissingDataException("Unable to set property $property_name as no entity has been provided.");
36 $this->entity->set($property_name, $value, $notify);
43 public function getProperties($include_computed = FALSE) {
44 if (!isset($this->entity)) {
45 throw new MissingDataException('Unable to get properties as no entity has been provided.');
47 return $this->getConfigTypedData()->getProperties($include_computed);
53 public function onChange($property_name) {
54 if (isset($this->entity)) {
55 // Let the entity know of any changes.
56 $this->getConfigTypedData()->onChange($property_name);
63 public function getIterator() {
64 if (isset($this->entity)) {
65 return $this->getConfigTypedData()->getIterator();
67 return new \ArrayIterator([]);
71 * Gets the typed data manager.
73 * @return \Drupal\Core\Config\TypedConfigManagerInterface
74 * The typed data manager.
76 public function getTypedDataManager() {
77 if (empty($this->typedDataManager)) {
78 $this->typedDataManager = \Drupal::service('config.typed');
81 return $this->typedDataManager;
87 public function applyDefaultValue($notify = TRUE) {
88 // @todo Figure out what to do for this method, see
89 // https://www.drupal.org/project/drupal/issues/2945635.
90 throw new \BadMethodCallException('Method not supported');
94 * Gets typed data for config entity.
96 * @return \Drupal\Core\TypedData\ComplexDataInterface
99 protected function getConfigTypedData() {
100 return $this->getTypedDataManager()->createFromNameAndData($this->entity->getConfigDependencyName(), $this->entity->toArray());