ConfigEntityInterface.php 7.2 KB

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