diff -u b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php --- b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php @@ -12,7 +12,6 @@ use Drupal\Core\Config\ConfigDuplicateUUIDException; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Language\Language; -use Drupal\Core\Plugin\PluginConfigDependencyInterface; /** * Defines a base configuration entity class. @@ -311,8 +310,13 @@ foreach($plugin_bag as $instance) { $definition = $instance->getPluginDefinition(); $this->addDependency('module', $definition['provider']); - if ($instance instanceof PluginConfigDependencyInterface) { - $instance->addConfigEntityDependency($this); + // Plugins can declare additional dependencies in their definition. + if (isset($definition['config_dependencies'])) { + foreach ($definition['config_dependencies'] as $type => $dependencies) { + foreach ($dependencies as $dependency) { + $this->addDependency($type, $dependency); + } + } } } } @@ -341,9 +345,20 @@ } /** - * {@inheritdoc} + * Creates a dependency. + * + * @param string $type + * The type of dependency being checked. Either 'module', 'theme', 'entity'. + * @param string $name + * If $type equals 'module' or 'theme' then it should be the name of the + * module or theme. In the case of entity it should be the full + * configuration object name. + * + * @see \Drupal\Core\Config\Entity\ConfigEntityInterface::getConfigDependencyName() + * + * @return $this */ - public function addDependency($type, $name) { + protected function addDependency($type, $name) { // A config entity is always dependent on its provider. There is no need to // explicitly declare the dependency. An explicit dependency on Core, which // provides some plugins, is also not needed. reverted: --- b/core/lib/Drupal/Core/Config/Entity/ConfigEntityInterface.php +++ a/core/lib/Drupal/Core/Config/Entity/ConfigEntityInterface.php @@ -153,24 +153,4 @@ */ public function getConfigDependencyName(); - /** - * Creates a dependency. - * - * This should only be called during as part of - * \Drupal\Core\Config\Entity\ConfigEntityInterface::calculateDependencies() - * since dependencies are recalculated on entity save. - * - * @param string $type - * The type of dependency being checked. Either 'module', 'theme', 'entity'. - * @param string $name - * If $type equals 'module' or 'theme' then it should be the name of the - * module or theme. In the case of entity it should be the full - * configuration object name. - * - * @return $this - * - * @see \Drupal\Core\Config\Entity\ConfigEntityInterface::getConfigDependencyName() - */ - public function addDependency($type, $name); - } reverted: --- b/core/lib/Drupal/Core/Plugin/PluginConfigDependencyInterface.php +++ /dev/null @@ -1,26 +0,0 @@ -setConstructorArgs(array($values, $this->entityTypeId)) ->setMethods(array('getPluginBag')) ->getMock(); - // Create a configurable plugin that would add a dependency. + + // Create a configurable plugin that would add dependencies. $instance_id = $this->randomName(); - $instance = new TestConfigurablePlugin(array(), $instance_id, array('provider' => 'test')); - $instance_dependency = $this->randomName(10); - $instance->setTestDependency($instance_dependency); + $instance_dependency_1 = $this->randomName(10); + $instance_dependency_2 = $this->randomName(11); + $plugin_definition = array( + 'provider' => 'test', + 'config_dependencies' => array( + 'entity' => array($instance_dependency_1), + 'module' => array($instance_dependency_2), + ) + ); + $instance = new TestConfigurablePlugin(array(), $instance_id, $plugin_definition); // Create a plugin bag to contain the instance. $plugin_bag = $this->getMockBuilder('\Drupal\Core\Plugin\DefaultPluginBag') @@ -118,7 +126,8 @@ $dependencies = $entity->calculateDependencies(); $this->assertContains('test', $dependencies['module']); $this->assertContains('stark', $dependencies['theme']); - $this->assertContains($instance_dependency, $dependencies['entity']); + $this->assertContains($instance_dependency_1, $dependencies['entity']); + $this->assertContains($instance_dependency_2, $dependencies['module']); } } reverted: --- b/core/modules/system/lib/Drupal/system/Plugin/Block/SystemMenuBlock.php +++ a/core/modules/system/lib/Drupal/system/Plugin/Block/SystemMenuBlock.php @@ -9,9 +9,7 @@ use Drupal\Component\Utility\NestedArray; use Drupal\block\BlockBase; -use Drupal\Core\Config\Entity\ConfigEntityInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; -use Drupal\Core\Plugin\PluginConfigDependencyInterface; use Drupal\menu_link\MenuTreeInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -26,7 +24,7 @@ * derivative = "Drupal\system\Plugin\Derivative\SystemMenuBlock" * ) */ +class SystemMenuBlock extends BlockBase implements ContainerFactoryPluginInterface { -class SystemMenuBlock extends BlockBase implements ContainerFactoryPluginInterface, PluginConfigDependencyInterface { /** * The menu tree. @@ -109,12 +107,4 @@ return array('cache_context.url', 'cache_context.user.roles'); } - /** - * {@inheritdoc} - */ - public function addConfigEntityDependency(ConfigEntityInterface $config_entity) { - $menu = \Drupal::entityManager()->getStorage('menu')->load($this->getDerivativeId()); - $config_entity->addDependency('entity', $menu->getConfigDependencyName()); - } - } reverted: --- b/core/modules/views_ui/lib/Drupal/views_ui/ViewUI.php +++ a/core/modules/views_ui/lib/Drupal/views_ui/ViewUI.php @@ -9,7 +9,6 @@ use Drupal\Component\Utility\String; use Drupal\Component\Utility\Timer; -use Drupal\Core\Config\Entity\ConfigEntityInterface; use Drupal\views\Views; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\views\ViewExecutable; @@ -1213,10 +1212,4 @@ public function getConfigDependencyName() { } - /** - * {@inheritdoc} - */ - public function addDependency($type, $name) { - } - } reverted: --- b/core/tests/Drupal/Tests/Core/Plugin/Fixtures/TestConfigurablePlugin.php +++ a/core/tests/Drupal/Tests/Core/Plugin/Fixtures/TestConfigurablePlugin.php @@ -9,17 +9,8 @@ use Drupal\Component\Plugin\ConfigurablePluginInterface; use Drupal\Component\Plugin\PluginBase; -use Drupal\Core\Config\Entity\ConfigEntityInterface; -use Drupal\Core\Plugin\PluginConfigDependencyInterface; +class TestConfigurablePlugin extends PluginBase implements ConfigurablePluginInterface { -class TestConfigurablePlugin extends PluginBase implements ConfigurablePluginInterface, PluginConfigDependencyInterface { - - /** - * A test dependency name to add using addConfigEntityDependency(); - * - * @var string - */ - protected $testDependency; /** * {@inheritdoc} @@ -42,18 +33,4 @@ return array(); } - public function setTestDependency($dependency) { - $this->testDependency = $dependency; - } - - /** - * Adds dependencies to config entity. - * - * @param ConfigEntityInterface $config_entity - * The config entity to add dependencies to. - */ - public function addConfigEntityDependency(ConfigEntityInterface $config_entity) { - $config_entity->addDependency('entity', $this->testDependency); - } - } only in patch2: unchanged: --- a/core/modules/system/lib/Drupal/system/Plugin/Derivative/SystemMenuBlock.php +++ b/core/modules/system/lib/Drupal/system/Plugin/Derivative/SystemMenuBlock.php @@ -52,6 +52,7 @@ public function getDerivativeDefinitions($base_plugin_definition) { foreach ($this->menuStorage->loadMultiple() as $menu => $entity) { $this->derivatives[$menu] = $base_plugin_definition; $this->derivatives[$menu]['admin_label'] = $entity->label(); + $this->derivatives[$menu]['config_dependencies']['entity'] = array($entity->getConfigDependencyName()); } return $this->derivatives; }