diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php index dd6481e..2a629ce 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php @@ -12,6 +12,7 @@ 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. @@ -310,6 +311,9 @@ public function calculateDependencies() { foreach($plugin_bag as $instance) { $definition = $instance->getPluginDefinition(); $this->addDependency('module', $definition['provider']); + if ($instance instanceof PluginConfigDependencyInterface) { + $instance->addConfigEntityDependency($this); + } } } return $this->dependencies; @@ -337,20 +341,9 @@ public function url($rel = 'edit-form', $options = array()) { } /** - * 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 + * {@inheritdoc} */ - protected function addDependency($type, $name) { + public 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. diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityInterface.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityInterface.php index f15a92b..846b174 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityInterface.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityInterface.php @@ -153,4 +153,23 @@ public function calculateDependencies(); */ 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. + * + * @see \Drupal\Core\Config\Entity\ConfigEntityInterface::getConfigDependencyName() + * + * @return $this + */ + public function addDependency($type, $name); } diff --git a/core/lib/Drupal/Core/Plugin/PluginConfigDependencyInterface.php b/core/lib/Drupal/Core/Plugin/PluginConfigDependencyInterface.php new file mode 100644 index 0000000..a5fbca0 --- /dev/null +++ b/core/lib/Drupal/Core/Plugin/PluginConfigDependencyInterface.php @@ -0,0 +1,26 @@ +randomName(); $instance = new TestConfigurablePlugin(array(), $instance_id, array('provider' => 'test')); + $instance_dependency = $this->randomName(10); + $instance->setTestDependency($instance_dependency); // Create a plugin bag to contain the instance. $plugin_bag = $this->getMockBuilder('\Drupal\Core\Plugin\DefaultPluginBag') @@ -116,6 +118,7 @@ public function testCalculateDependencies() { $dependencies = $entity->calculateDependencies(); $this->assertContains('test', $dependencies['module']); $this->assertContains('stark', $dependencies['theme']); + $this->assertContains($instance_dependency, $dependencies['entity']); } } diff --git a/core/modules/system/lib/Drupal/system/Plugin/Block/SystemMenuBlock.php b/core/modules/system/lib/Drupal/system/Plugin/Block/SystemMenuBlock.php index 32a84d7..42a3314 100644 --- a/core/modules/system/lib/Drupal/system/Plugin/Block/SystemMenuBlock.php +++ b/core/modules/system/lib/Drupal/system/Plugin/Block/SystemMenuBlock.php @@ -9,7 +9,9 @@ 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; @@ -24,7 +26,7 @@ * derivative = "Drupal\system\Plugin\Derivative\SystemMenuBlock" * ) */ -class SystemMenuBlock extends BlockBase implements ContainerFactoryPluginInterface { +class SystemMenuBlock extends BlockBase implements ContainerFactoryPluginInterface, PluginConfigDependencyInterface { /** * The menu tree. @@ -107,4 +109,12 @@ protected function getRequiredCacheContexts() { 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()); + } + } diff --git a/core/modules/system/lib/Drupal/system/Tests/Block/SystemMenuBlockTest.php b/core/modules/system/lib/Drupal/system/Tests/Block/SystemMenuBlockTest.php new file mode 100644 index 0000000..11af793 --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Tests/Block/SystemMenuBlockTest.php @@ -0,0 +1,66 @@ + 'System menu block test', + 'description' => 'Tests \Drupal\system\Plugin\Block\SystemMenuBlock.', + 'group' => 'System blocks', + ); + } + + public function testSystemMenuBlockConfigDependencies() { + // Add a new custom menu. + $menu_name = $this->randomName(16); + $label = $this->randomName(16); + + $menu = entity_create('menu', array( + 'id' => $menu_name, + 'label' => $label, + 'description' => 'Description text', + )); + $menu->save(); + + $block = entity_create('block', array( + 'plugin' => 'system_menu_block:'. $menu->id(), + 'region' => 'footer', + 'id' => 'machinename', + 'theme' => 'stark', + )); + + $dependencies = $block->calculateDependencies(); + $expected = array( + 'entity' => array( + 'system.menu.' . $menu->id() + ), + 'module' => array( + 'system' + ), + 'theme' => array( + 'stark' + ), + ); + $this->assertIdentical($expected, $dependencies); + } +} diff --git a/core/modules/views_ui/lib/Drupal/views_ui/ViewUI.php b/core/modules/views_ui/lib/Drupal/views_ui/ViewUI.php index 3d49837..5c45ccf 100644 --- a/core/modules/views_ui/lib/Drupal/views_ui/ViewUI.php +++ b/core/modules/views_ui/lib/Drupal/views_ui/ViewUI.php @@ -9,6 +9,7 @@ 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; @@ -1212,4 +1213,10 @@ public function calculateDependencies() { public function getConfigDependencyName() { } + /** + * {@inheritdoc} + */ + public function addDependency($type, $name) { + } + } diff --git a/core/profiles/minimal/config/block.block.stark_admin.yml b/core/profiles/minimal/config/block.block.stark_admin.yml index 0895e7e..5d5c2c1 100644 --- a/core/profiles/minimal/config/block.block.stark_admin.yml +++ b/core/profiles/minimal/config/block.block.stark_admin.yml @@ -18,6 +18,8 @@ visibility: node_type: types: { } dependencies: + entity: + - system.menu.admin module: - system theme: diff --git a/core/profiles/minimal/config/block.block.stark_tools.yml b/core/profiles/minimal/config/block.block.stark_tools.yml index c9ff31b..36481b3 100644 --- a/core/profiles/minimal/config/block.block.stark_tools.yml +++ b/core/profiles/minimal/config/block.block.stark_tools.yml @@ -18,6 +18,8 @@ visibility: node_type: types: { } dependencies: + entity: + - system.menu.tools module: - system theme: diff --git a/core/profiles/standard/config/block.block.bartik_footer.yml b/core/profiles/standard/config/block.block.bartik_footer.yml index 85451c7..ef96ea9 100644 --- a/core/profiles/standard/config/block.block.bartik_footer.yml +++ b/core/profiles/standard/config/block.block.bartik_footer.yml @@ -20,6 +20,8 @@ visibility: article: '0' page: '0' dependencies: + entity: + - system.menu.footer module: - system theme: diff --git a/core/profiles/standard/config/block.block.bartik_tools.yml b/core/profiles/standard/config/block.block.bartik_tools.yml index 6300b79..12efff1 100644 --- a/core/profiles/standard/config/block.block.bartik_tools.yml +++ b/core/profiles/standard/config/block.block.bartik_tools.yml @@ -20,6 +20,8 @@ visibility: article: '0' page: '0' dependencies: + entity: + - system.menu.tools module: - system theme: diff --git a/core/tests/Drupal/Tests/Core/Plugin/Fixtures/TestConfigurablePlugin.php b/core/tests/Drupal/Tests/Core/Plugin/Fixtures/TestConfigurablePlugin.php index c12ce74..6a76133 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/Fixtures/TestConfigurablePlugin.php +++ b/core/tests/Drupal/Tests/Core/Plugin/Fixtures/TestConfigurablePlugin.php @@ -9,8 +9,17 @@ 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} @@ -33,4 +42,18 @@ public function defaultConfiguration() { 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); + } + }