3 namespace Drupal\Core\Config\Entity;
5 use Drupal\Core\Config\Entity\Exception\ConfigEntityStorageClassException;
6 use Drupal\Core\Entity\EntityType;
7 use Drupal\Core\Config\ConfigPrefixLengthException;
10 * Provides an implementation of a configuration entity type and its metadata.
12 class ConfigEntityType extends EntityType implements ConfigEntityTypeInterface {
15 * The config prefix set in the configuration entity type annotation.
17 * @see \Drupal\Core\Config\Entity\ConfigEntityTypeInterface::getConfigPrefix()
19 protected $config_prefix;
24 protected $static_cache = FALSE;
27 * Keys that are stored key value store for fast lookup.
31 protected $lookup_keys = [];
34 * The list of configuration entity properties to export from the annotation.
38 protected $config_export = [];
41 * The result of merging config_export annotation with the defaults.
43 * This is stored on the class so that it does not have to be recalculated.
47 protected $mergedConfigExport = [];
52 * @throws \Drupal\Core\Config\Entity\Exception\ConfigEntityStorageClassException
53 * Exception thrown when the provided class is not an instance of
54 * \Drupal\Core\Config\Entity\ConfigEntityStorage.
56 public function __construct($definition) {
57 // Ensure a default list cache tag is set; do this before calling the parent
58 // constructor, because we want "Configuration System style" cache tags.
59 if (empty($this->list_cache_tags)) {
60 $this->list_cache_tags = ['config:' . $definition['id'] . '_list'];
63 parent::__construct($definition);
64 // Always add a default 'uuid' key.
65 $this->entity_keys['uuid'] = 'uuid';
66 $this->entity_keys['langcode'] = 'langcode';
68 'storage' => 'Drupal\Core\Config\Entity\ConfigEntityStorage',
70 $this->lookup_keys[] = 'uuid';
76 public function getConfigPrefix() {
77 // Ensure that all configuration entities are prefixed by the name of the
78 // module that provides the configuration entity type.
79 if (isset($this->config_prefix)) {
80 $config_prefix = $this->provider . '.' . $this->config_prefix;
83 $config_prefix = $this->provider . '.' . $this->id();
86 if (strlen($config_prefix) > static::PREFIX_LENGTH) {
87 throw new ConfigPrefixLengthException("The configuration file name prefix $config_prefix exceeds the maximum character limit of " . static::PREFIX_LENGTH);
89 return $config_prefix;
95 public function getBaseTable() {
102 public function getRevisionDataTable() {
109 public function getRevisionTable() {
116 public function getDataTable() {
123 public function getConfigDependencyKey() {
130 * @throws \Drupal\Core\Config\Entity\Exception\ConfigEntityStorageClassException
131 * Exception thrown when the provided class is not an instance of
132 * \Drupal\Core\Config\Entity\ConfigEntityStorage.
134 * @see \Drupal\Core\Config\Entity\ConfigEntityStorage
136 protected function checkStorageClass($class) {
137 if (!is_a($class, 'Drupal\Core\Config\Entity\ConfigEntityStorage', TRUE)) {
138 throw new ConfigEntityStorageClassException("$class is not \\Drupal\\Core\\Config\\Entity\\ConfigEntityStorage or it does not extend it");
145 public function getPropertiesToExport() {
146 if (!empty($this->config_export)) {
147 if (empty($this->mergedConfigExport)) {
148 // Always add default properties to be exported.
149 $this->mergedConfigExport = [
151 'langcode' => 'langcode',
152 'status' => 'status',
153 'dependencies' => 'dependencies',
154 'third_party_settings' => 'third_party_settings',
157 foreach ($this->config_export as $property => $name) {
158 if (is_numeric($property)) {
159 $this->mergedConfigExport[$name] = $name;
162 $this->mergedConfigExport[$property] = $name;
166 return $this->mergedConfigExport;
174 public function getLookupKeys() {
175 return $this->lookup_keys;