diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigDependencyManager.php b/core/lib/Drupal/Core/Config/Entity/ConfigDependencyManager.php index 43df7b2..14eac1d 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigDependencyManager.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigDependencyManager.php @@ -14,38 +14,35 @@ * Provides a class to discover configuration entity dependencies. * * Configuration entities can depend on modules, themes and other configuration - * entities. The dependency system is used during configuration installation - * and removal to ensure that configuration entities are handled in the correct - * order. For example, node types are created before their fields, and both are - * created before the view display configuration. + * entities. The dependency system is used during configuration installation, + * uninstallation and synchronization to ensure that configuration entities are + * handled in the correct order. For example, node types are created before + * their fields, and both are created before the view display configuration. * - * Configuration entities need to declare their dependencies, and if they are - * part of extensions (modules, themes, or profiles), the extension also needs - * to ensure that the extensions the configuration depends on are present. For - * example, if a view configuration is part of a profile and the view will not - * work without a certain module (for example, a module that provides a field - * that the view uses), the profile must declare a dependency on this module in - * its info file. If you find that you do not want your extension to always - * depend on a particular module that one of your configuration items depends - * on, you can use a sub-module: move the configuration item to the sub-module, - * instead of including it in the main extension, and declare the module - * dependency in the sub-module only. + * If a configuration entity is provided as default configuration by an + * extension (modules, themes, or profiles), the extension has to depend on any + * modules or themes that the configuration depends on. For example, if a view + * configuration entity is provided by an installation profile and the view will + * not work without a certain module, the profile must declare a dependency on + * this module in its info.yml file. If you do not want your extension to always + * depend on a particular module that one of the default configuration entities + * depends on, you can use a sub-module: move the configuration entity to the + * sub-module instead of including it in the main extension, and declare the + * module dependency in the sub-module only. * * Classes for configuration entities with dependencies normally extend * \Drupal\Core\Config\Entity\ConfigEntityBase or at least use * \Drupal\Core\Plugin\PluginDependencyTrait to manage dependencies. The class * must implement * \Drupal\Core\Config\Entity\ConfigEntityInterface::calculateDependencies(), - * which should calculate (and return) the dependencies, and also call the - * \Drupal\Core\Config\Entity\ConfigEntityBase::addDependency() method for each - * calculated dependency. - * \Drupal\Core\Config\Entity\ConfigEntityBase::calculateDependencies() provides - * a good starting point to call from your implementation, as it will discover - * dependencies coming from plugins in plugin bags and third party settings. - * During dependency checking, the entity class's implementation of - * \Drupal\Core\Config\Entity\ConfigEntityInterface::getDependencies() will be - * called; the base implementation will return the array of all dependencies - * added by calls to addDependency() methods. + * which should calculate (and return) the dependencies. Use + * \Drupal\Core\Config\Entity\ConfigEntityBase::addDependency() to add + * dependencies. Most implementations call + * \Drupal\Core\Config\Entity\ConfigEntityBase::calculateDependencies() since it + * provides a generic implementation that will discover dependencies due to + * plugins and third party settings. To get a configuration entities current + * dependencies without forcing a recalculation use + * \Drupal\Core\Config\Entity\ConfigEntityInterface::getDependencies(). * * Classes for configurable plugins are a special case. They can either declare * their configuration dependencies using the calculateDependencies() method @@ -59,10 +56,9 @@ * configuration in the staging directory before the synchronization has * occurred. * - * When an item that configuration can depend on is removed, such as when - * uninstalling a module, configuration that is dependent will also be - * removed. This default behavior could lead to undesirable side effects, such - * as a node view mode configuration being entirely removed when the module + * When uninstalling a module or a theme, configuration entities that are + * dependent will also be removed. This default behavior can lead to undesirable + * side effects, such as a node view mode being entirely removed when the module * defining a field or formatter it uses is uninstalled. To prevent this, * configuration entity classes can implement * \Drupal\Core\Config\Entity\ConfigEntityInterface::onDependencyRemoval(), @@ -77,7 +73,8 @@ * @see \Drupal\Core\Config\Entity\ConfigEntityInterface::getConfigDependencyName() * @see \Drupal\Core\Config\Entity\ConfigEntityInterface::onDependencyRemoval() * @see \Drupal\Core\Config\Entity\ConfigEntityBase::addDependency() - * @see \Drupal\Core\Config\ConfigInstaller::installDefaultConfig() + * @see \Drupal\Core\Config\ConfigInstallerInterface::installDefaultConfig() + * @see \Drupal\Core\Config\ConfigManagerInterface::uninstall() * @see \Drupal\Core\Config\Entity\ConfigEntityDependency * @see \Drupal\Core\Plugin\PluginDependencyTrait */ diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php index 7e2c7c0..ea1c570 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php @@ -367,6 +367,10 @@ public function link($text = NULL, $rel = 'edit-form', array $options = []) { /** * Overrides \Drupal\Core\Entity\DependencyTrait:addDependency(). * + * Note that this function should only be called from implementation of + * \Drupal\Core\Config\Entity\ConfigEntityInterface::calculateDependencies() + * as dependencies are recalculated during every entity save. + * * @see \Drupal\Core\Config\Entity\ConfigEntityDependency::hasDependency() */ protected function addDependency($type, $name) {