123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- <?php
- namespace Drupal\Core\Config\Entity;
- use Drupal\Core\Config\Entity\Exception\ConfigEntityStorageClassException;
- use Drupal\Core\Entity\EntityType;
- use Drupal\Core\Config\ConfigPrefixLengthException;
- /**
- * Provides an implementation of a configuration entity type and its metadata.
- */
- class ConfigEntityType extends EntityType implements ConfigEntityTypeInterface {
- /**
- * The config prefix set in the configuration entity type annotation.
- *
- * @see \Drupal\Core\Config\Entity\ConfigEntityTypeInterface::getConfigPrefix()
- */
- protected $config_prefix;
- /**
- * {@inheritdoc}
- */
- protected $static_cache = FALSE;
- /**
- * Keys that are stored key value store for fast lookup.
- *
- * @var array
- */
- protected $lookup_keys = [];
- /**
- * The list of configuration entity properties to export from the annotation.
- *
- * @var array
- */
- protected $config_export = [];
- /**
- * The result of merging config_export annotation with the defaults.
- *
- * This is stored on the class so that it does not have to be recalculated.
- *
- * @var array
- */
- protected $mergedConfigExport = [];
- /**
- * {@inheritdoc}
- *
- * @throws \Drupal\Core\Config\Entity\Exception\ConfigEntityStorageClassException
- * Exception thrown when the provided class is not an instance of
- * \Drupal\Core\Config\Entity\ConfigEntityStorage.
- */
- public function __construct($definition) {
- // Ensure a default list cache tag is set; do this before calling the parent
- // constructor, because we want "Configuration System style" cache tags.
- if (empty($this->list_cache_tags)) {
- $this->list_cache_tags = ['config:' . $definition['id'] . '_list'];
- }
- parent::__construct($definition);
- // Always add a default 'uuid' key.
- $this->entity_keys['uuid'] = 'uuid';
- $this->entity_keys['langcode'] = 'langcode';
- $this->handlers += [
- 'storage' => 'Drupal\Core\Config\Entity\ConfigEntityStorage',
- ];
- $this->lookup_keys[] = 'uuid';
- }
- /**
- * {@inheritdoc}
- */
- public function getConfigPrefix() {
- // Ensure that all configuration entities are prefixed by the name of the
- // module that provides the configuration entity type.
- if (isset($this->config_prefix)) {
- $config_prefix = $this->provider . '.' . $this->config_prefix;
- }
- else {
- $config_prefix = $this->provider . '.' . $this->id();
- }
- if (strlen($config_prefix) > static::PREFIX_LENGTH) {
- throw new ConfigPrefixLengthException("The configuration file name prefix $config_prefix exceeds the maximum character limit of " . static::PREFIX_LENGTH);
- }
- return $config_prefix;
- }
- /**
- * {@inheritdoc}
- */
- public function getBaseTable() {
- return FALSE;
- }
- /**
- * {@inheritdoc}
- */
- public function getRevisionDataTable() {
- return FALSE;
- }
- /**
- * {@inheritdoc}
- */
- public function getRevisionTable() {
- return FALSE;
- }
- /**
- * {@inheritdoc}
- */
- public function getDataTable() {
- return FALSE;
- }
- /**
- * {@inheritdoc}
- */
- public function getConfigDependencyKey() {
- return 'config';
- }
- /**
- * {@inheritdoc}
- *
- * @throws \Drupal\Core\Config\Entity\Exception\ConfigEntityStorageClassException
- * Exception thrown when the provided class is not an instance of
- * \Drupal\Core\Config\Entity\ConfigEntityStorage.
- *
- * @see \Drupal\Core\Config\Entity\ConfigEntityStorage
- */
- protected function checkStorageClass($class) {
- if (!is_a($class, 'Drupal\Core\Config\Entity\ConfigEntityStorage', TRUE)) {
- throw new ConfigEntityStorageClassException("$class is not \\Drupal\\Core\\Config\\Entity\\ConfigEntityStorage or it does not extend it");
- }
- }
- /**
- * {@inheritdoc}
- */
- public function getPropertiesToExport() {
- if (!empty($this->config_export)) {
- if (empty($this->mergedConfigExport)) {
- // Always add default properties to be exported.
- $this->mergedConfigExport = [
- 'uuid' => 'uuid',
- 'langcode' => 'langcode',
- 'status' => 'status',
- 'dependencies' => 'dependencies',
- 'third_party_settings' => 'third_party_settings',
- '_core' => '_core',
- ];
- foreach ($this->config_export as $property => $name) {
- if (is_numeric($property)) {
- $this->mergedConfigExport[$name] = $name;
- }
- else {
- $this->mergedConfigExport[$property] = $name;
- }
- }
- }
- return $this->mergedConfigExport;
- }
- return NULL;
- }
- /**
- * {@inheritdoc}
- */
- public function getLookupKeys() {
- return $this->lookup_keys;
- }
- }
|