ConfigEntityAdapter.php in Drupal 8
File
core/lib/Drupal/Core/Entity/Plugin/DataType/ConfigEntityAdapter.php
View source
<?php
namespace Drupal\Core\Entity\Plugin\DataType;
use Drupal\Core\Config\TypedConfigManagerInterface;
use Drupal\Core\TypedData\Exception\MissingDataException;
use Drupal\Core\TypedData\TypedDataManagerInterface;
class ConfigEntityAdapter extends EntityAdapter {
protected $entity;
protected $typedConfigManager;
public function get($property_name) {
if (!isset($this->entity)) {
throw new MissingDataException("Unable to get property {$property_name} as no entity has been provided.");
}
return $this
->getConfigTypedData()
->get($property_name);
}
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;
}
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);
}
public function onChange($property_name) {
if (isset($this->entity)) {
$this
->getConfigTypedData()
->onChange($property_name);
}
}
public function getIterator() {
if (isset($this->entity)) {
return $this
->getConfigTypedData()
->getIterator();
}
return new \ArrayIterator([]);
}
protected function getTypedConfigManager() {
if (empty($this->typedConfigManager)) {
$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;
}
public function getTypedDataManager() {
if (empty($this->typedDataManager)) {
$this->typedDataManager = \Drupal::service('config.typed');
}
return $this->typedDataManager;
}
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;
}
public function applyDefaultValue($notify = TRUE) {
throw new \BadMethodCallException('Method not supported');
}
protected function getConfigTypedData() {
return $this
->getTypedConfigManager()
->createFromNameAndData($this->entity
->getConfigDependencyName(), $this->entity
->toArray());
}
}