8931f1ed04927b99479851834774296f98f773dd
[yaffs-website] / web / core / lib / Drupal / Core / Config / Entity / ConfigEntityInterface.php
1 <?php
2
3 namespace Drupal\Core\Config\Entity;
4
5 use Drupal\Core\Entity\EntityInterface;
6
7 /**
8  * Defines a common interface for configuration entities.
9  *
10  * @ingroup config_api
11  * @ingroup entity_api
12  */
13 interface ConfigEntityInterface extends EntityInterface, ThirdPartySettingsInterface {
14
15   /**
16    * Enables the configuration entity.
17    *
18    * @return $this
19    */
20   public function enable();
21
22   /**
23    * Disables the configuration entity.
24    *
25    * @return $this
26    */
27   public function disable();
28
29   /**
30    * Sets the status of the configuration entity.
31    *
32    * @param bool $status
33    *   The status of the configuration entity.
34    *
35    * @return $this
36    */
37   public function setStatus($status);
38
39   /**
40    * Sets the status of the isSyncing flag.
41    *
42    * @param bool $status
43    *   The status of the sync flag.
44    *
45    * @return $this
46    */
47   public function setSyncing($status);
48
49   /**
50    * Returns whether the configuration entity is enabled.
51    *
52    * Status implementations for configuration entities should follow these
53    * general rules:
54    *   - Status does not affect the loading of entities. I.e. Disabling
55    *     configuration entities should only have UI/access implications.
56    *   - It should only take effect when a 'status' key is explicitly declared
57    *     in the entity_keys info of a configuration entity's annotation data.
58    *   - Each entity implementation (entity/controller) is responsible for
59    *     checking and managing the status.
60    *
61    * @return bool
62    *   Whether the entity is enabled or not.
63    */
64   public function status();
65
66   /**
67    * Returns whether this entity is being changed as part of an import process.
68    *
69    * If you are writing code that responds to a change in this entity (insert,
70    * update, delete, presave, etc.), and your code would result in a
71    * configuration change (whether related to this configuration entity, another
72    * configuration entity, or non-entity configuration) or your code would
73    * result in a change to this entity itself, you need to check and see if this
74    * entity change is part of an import process, and skip executing your code if
75    * that is the case.
76    *
77    * For example, \Drupal\node\Entity\NodeType::postSave() adds the default body
78    * field to newly created node type configuration entities, which is a
79    * configuration change. You would not want this code to run during an import,
80    * because imported entities were already given the body field when they were
81    * originally created, and the imported configuration includes all of their
82    * currently-configured fields. On the other hand,
83    * \Drupal\field\Entity\FieldStorageConfig::preSave() and the methods it calls
84    * make sure that the storage tables are created or updated for the field
85    * storage configuration entity, which is not a configuration change, and it
86    * must be done whether due to an import or not. So, the first method should
87    * check $entity->isSyncing() and skip executing if it returns TRUE, and the
88    * second should not perform this check.
89    *
90    * @return bool
91    *   TRUE if the configuration entity is being created, updated, or deleted
92    *   through the import process.
93    */
94   public function isSyncing();
95
96   /**
97    * Returns whether this entity is being changed during the uninstall process.
98    *
99    * If you are writing code that responds to a change in this entity (insert,
100    * update, delete, presave, etc.), and your code would result in a
101    * configuration change (whether related to this configuration entity, another
102    * configuration entity, or non-entity configuration) or your code would
103    * result in a change to this entity itself, you need to check and see if this
104    * entity change is part of an uninstall process, and skip executing your code
105    * if that is the case.
106    *
107    * For example, \Drupal\language\Entity\ConfigurableLanguage::preDelete()
108    * prevents the API from deleting the default language. However during an
109    * uninstall of the language module it is expected that the default language
110    * should be deleted.
111    *
112    * @return bool
113    */
114   public function isUninstalling();
115
116   /**
117    * Returns the value of a property.
118    *
119    * @param string $property_name
120    *   The name of the property that should be returned.
121    *
122    * @return mixed
123    *   The property if it exists, or NULL otherwise.
124    */
125   public function get($property_name);
126
127   /**
128    * Sets the value of a property.
129    *
130    * @param string $property_name
131    *   The name of the property that should be set.
132    * @param mixed $value
133    *   The value the property should be set to.
134    *
135    * @return $this
136    */
137   public function set($property_name, $value);
138
139   /**
140    * Calculates dependencies and stores them in the dependency property.
141    *
142    * @return $this
143    *
144    * @see \Drupal\Core\Config\Entity\ConfigDependencyManager
145    */
146   public function calculateDependencies();
147
148   /**
149    * Informs the entity that entities it depends on will be deleted.
150    *
151    * This method allows configuration entities to remove dependencies instead
152    * of being deleted themselves. Configuration entities can use this method to
153    * avoid being unnecessarily deleted during an extension uninstallation.
154    * For example, entity displays remove references to widgets and formatters if
155    * the plugin that supplies them depends on a module that is being
156    * uninstalled.
157    *
158    * If this method returns TRUE then the entity needs to be re-saved by the
159    * caller for the changes to take effect. Implementations should not save the
160    * entity.
161    *
162    * @param array $dependencies
163    *   An array of dependencies that will be deleted keyed by dependency type.
164    *   Dependency types are, for example, entity, module and theme.
165    *
166    * @return bool
167    *   TRUE if the entity has been changed as a result, FALSE if not.
168    *
169    * @see \Drupal\Core\Config\Entity\ConfigDependencyManager
170    * @see \Drupal\Core\Config\ConfigEntityBase::preDelete()
171    * @see \Drupal\Core\Config\ConfigManager::uninstall()
172    * @see \Drupal\Core\Entity\EntityDisplayBase::onDependencyRemoval()
173    */
174   public function onDependencyRemoval(array $dependencies);
175
176   /**
177    * Gets the configuration dependencies.
178    *
179    * @return array
180    *   An array of dependencies, keyed by $type.
181    *
182    * @see \Drupal\Core\Config\Entity\ConfigDependencyManager
183    */
184   public function getDependencies();
185
186   /**
187    * Checks whether this entity is installable.
188    *
189    * For example, a default view might not be installable if the base table
190    * doesn't exist.
191    *
192    * @return bool
193    *   TRUE if the entity is installable, FALSE otherwise.
194    */
195   public function isInstallable();
196
197   /**
198    * Sets that the data should be trusted.
199    *
200    * If the data is trusted then dependencies will not be calculated on save and
201    * schema will not be used to cast the values. Generally this is only used
202    * during module and theme installation. Once the config entity has been saved
203    * the data will no longer be marked as trusted. This is an optimization for
204    * creation of configuration during installation.
205    *
206    * @return $this
207    *
208    * @see \Drupal\Core\Config\ConfigInstaller::createConfiguration()
209    */
210   public function trustData();
211
212   /**
213    * Gets whether on not the data is trusted.
214    *
215    * @return bool
216    *   TRUE if the configuration data is trusted, FALSE if not.
217    */
218   public function hasTrustedData();
219
220 }