X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Flib%2FDrupal%2FCore%2FEntity%2FPlugin%2FDataType%2FConfigEntityAdapter.php;fp=web%2Fcore%2Flib%2FDrupal%2FCore%2FEntity%2FPlugin%2FDataType%2FConfigEntityAdapter.php;h=093c77dd16b110db2f1f78c7852e155d87243002;hp=0000000000000000000000000000000000000000;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hpb=74df008bdbb3a11eeea356744f39b802369bda3c diff --git a/web/core/lib/Drupal/Core/Entity/Plugin/DataType/ConfigEntityAdapter.php b/web/core/lib/Drupal/Core/Entity/Plugin/DataType/ConfigEntityAdapter.php new file mode 100644 index 000000000..093c77dd1 --- /dev/null +++ b/web/core/lib/Drupal/Core/Entity/Plugin/DataType/ConfigEntityAdapter.php @@ -0,0 +1,103 @@ +entity)) { + throw new MissingDataException("Unable to get property $property_name as no entity has been provided."); + } + return $this->getConfigTypedData()->get($property_name); + } + + /** + * {@inheritdoc} + */ + public function set($property_name, $value, $notify = TRUE) { + if (!isset($this->entity)) { + throw new MissingDataException("Unable to set property $property_name as no entity has been provided."); + } + $this->entity->set($property_name, $value, $notify); + return $this; + } + + /** + * {@inheritdoc} + */ + public function getProperties($include_computed = FALSE) { + if (!isset($this->entity)) { + throw new MissingDataException('Unable to get properties as no entity has been provided.'); + } + return $this->getConfigTypedData()->getProperties($include_computed); + } + + /** + * {@inheritdoc} + */ + public function onChange($property_name) { + if (isset($this->entity)) { + // Let the entity know of any changes. + $this->getConfigTypedData()->onChange($property_name); + } + } + + /** + * {@inheritdoc} + */ + public function getIterator() { + if (isset($this->entity)) { + return $this->getConfigTypedData()->getIterator(); + } + return new \ArrayIterator([]); + } + + /** + * Gets the typed data manager. + * + * @return \Drupal\Core\Config\TypedConfigManagerInterface + * The typed data manager. + */ + public function getTypedDataManager() { + if (empty($this->typedDataManager)) { + $this->typedDataManager = \Drupal::service('config.typed'); + } + + return $this->typedDataManager; + } + + /** + * {@inheritdoc} + */ + public function applyDefaultValue($notify = TRUE) { + // @todo Figure out what to do for this method, see + // https://www.drupal.org/project/drupal/issues/2945635. + throw new \BadMethodCallException('Method not supported'); + } + + /** + * Gets typed data for config entity. + * + * @return \Drupal\Core\TypedData\ComplexDataInterface + * The typed data. + */ + protected function getConfigTypedData() { + return $this->getTypedDataManager()->createFromNameAndData($this->entity->getConfigDependencyName(), $this->entity->toArray()); + } + +}