11c9ff1bf093005fc75e20bb51d9fc1aef5a25fa
[yaffs-website] / web / core / lib / Drupal / Core / Config / Entity / ConfigEntityType.php
1 <?php
2
3 namespace Drupal\Core\Config\Entity;
4
5 use Drupal\Core\Config\Entity\Exception\ConfigEntityStorageClassException;
6 use Drupal\Core\Entity\EntityType;
7 use Drupal\Core\Config\ConfigPrefixLengthException;
8
9 /**
10  * Provides an implementation of a configuration entity type and its metadata.
11  */
12 class ConfigEntityType extends EntityType implements ConfigEntityTypeInterface {
13
14   /**
15    * The config prefix set in the configuration entity type annotation.
16    *
17    * @see \Drupal\Core\Config\Entity\ConfigEntityTypeInterface::getConfigPrefix()
18    */
19   protected $config_prefix;
20
21   /**
22    * {@inheritdoc}
23    */
24   protected $static_cache = FALSE;
25
26   /**
27    * Keys that are stored key value store for fast lookup.
28    *
29    * @var array
30    */
31   protected $lookup_keys = [];
32
33   /**
34    * The list of configuration entity properties to export from the annotation.
35    *
36    * @var array
37    */
38   protected $config_export = [];
39
40   /**
41    * The result of merging config_export annotation with the defaults.
42    *
43    * This is stored on the class so that it does not have to be recalculated.
44    *
45    * @var array
46    */
47   protected $mergedConfigExport = [];
48
49   /**
50    * {@inheritdoc}
51    *
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.
55    */
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'];
61     }
62
63     parent::__construct($definition);
64     // Always add a default 'uuid' key.
65     $this->entity_keys['uuid'] = 'uuid';
66     $this->entity_keys['langcode'] = 'langcode';
67     $this->handlers += [
68       'storage' => 'Drupal\Core\Config\Entity\ConfigEntityStorage',
69     ];
70     $this->lookup_keys[] = 'uuid';
71   }
72
73   /**
74    * {@inheritdoc}
75    */
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;
81     }
82     else {
83       $config_prefix = $this->provider . '.' . $this->id();
84     }
85
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);
88     }
89     return $config_prefix;
90   }
91
92   /**
93    * {@inheritdoc}
94    */
95   public function getBaseTable() {
96     return FALSE;
97   }
98
99   /**
100    * {@inheritdoc}
101    */
102   public function getRevisionDataTable() {
103     return FALSE;
104   }
105
106   /**
107    * {@inheritdoc}
108    */
109   public function getRevisionTable() {
110     return FALSE;
111   }
112
113   /**
114    * {@inheritdoc}
115    */
116   public function getDataTable() {
117     return FALSE;
118   }
119
120   /**
121    * {@inheritdoc}
122    */
123   public function getConfigDependencyKey() {
124     return 'config';
125   }
126
127   /**
128    * {@inheritdoc}
129    *
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.
133    *
134    * @see \Drupal\Core\Config\Entity\ConfigEntityStorage
135    */
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");
139     }
140   }
141
142   /**
143    * {@inheritdoc}
144    */
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 = [
150           'uuid' => 'uuid',
151           'langcode' => 'langcode',
152           'status' => 'status',
153           'dependencies' => 'dependencies',
154           'third_party_settings' => 'third_party_settings',
155           '_core' => '_core',
156         ];
157         foreach ($this->config_export as $property => $name) {
158           if (is_numeric($property)) {
159             $this->mergedConfigExport[$name] = $name;
160           }
161           else {
162             $this->mergedConfigExport[$property] = $name;
163           }
164         }
165       }
166       return $this->mergedConfigExport;
167     }
168     return NULL;
169   }
170
171   /**
172    * {@inheritdoc}
173    */
174   public function getLookupKeys() {
175     return $this->lookup_keys;
176   }
177
178 }