From 6e0225e3041010e4f0268d927802a36fc20a0a8a Mon Sep 17 00:00:00 2001
From: Nathaniel Catchpole <catch@35733.no-reply.drupal.org>
Date: Mon, 5 Oct 2015 16:26:08 +0100
Subject: [PATCH] Issue #2520540 by alexpott: Enforced configuration
 dependencies shouldn't have to be repeated in the calculated dependencies

---
 core/lib/Drupal/Core/Config/ConfigManager.php |  6 +++-
 .../Config/Entity/ConfigDependencyManager.php | 11 +++---
 .../Core/Config/Entity/ConfigEntityBase.php   | 25 ++++++-------
 .../Config/Entity/ConfigEntityDependency.php  | 17 +++++----
 .../Config/Entity/ConfigEntityInterface.php   |  3 +-
 .../Drupal/Core/Entity/EntityDisplayBase.php  |  2 +-
 .../Core/Entity/EntityDisplayModeBase.php     |  2 +-
 .../lib/Drupal/Core/Field/FieldConfigBase.php |  2 +-
 core/modules/block/src/Entity/Block.php       |  2 +-
 .../src/Unit/BlockConfigEntityUnitTest.php    |  2 +-
 .../core.entity_view_mode.node.print.yml      |  1 -
 .../book/config/install/node.type.book.yml    |  2 --
 .../config/src/Tests/ConfigDependencyTest.php | 11 +++---
 .../src/Tests/ConfigDependencyWebTest.php     |  4 +--
 ...g_test.dynamic.other_module_test_unmet.yml |  2 --
 core/modules/editor/src/Entity/Editor.php     |  2 +-
 .../src/Unit/EditorConfigEntityUnitTest.php   |  2 +-
 core/modules/field/src/Entity/FieldConfig.php |  2 +-
 .../field/src/Entity/FieldStorageConfig.php   |  2 +-
 .../src/Unit/FieldConfigEntityUnitTest.php    |  2 +-
 .../Unit/FieldStorageConfigEntityUnitTest.php |  2 +-
 .../field_ui/src/Tests/EntityDisplayTest.php  |  4 +--
 .../field_ui/src/Tests/ManageDisplayTest.php  |  4 +--
 .../Views/RelationshipUserFileDataTest.php    |  2 +-
 .../forum/config/install/node.type.forum.yml  |  2 --
 .../install/taxonomy.vocabulary.forums.yml    |  2 --
 .../Views/RelationshipUserImageDataTest.php   |  2 +-
 .../src/Entity/ContentLanguageSettings.php    |  2 +-
 .../Unit/ContentLanguageSettingsUnitTest.php  |  2 +-
 core/modules/migrate/src/Entity/Migration.php |  2 +-
 .../node/src/Tests/Views/FrontPageTest.php    |  2 +-
 core/modules/rdf/src/Entity/RdfMapping.php    |  2 +-
 .../Unit/RdfMappingConfigEntityUnitTest.php   |  4 +--
 .../src/Entity/ResponsiveImageStyle.php       |  2 +-
 ...sponsiveImageStyleConfigEntityUnitTest.php |  2 +-
 .../src/Tests/Action/ActionUnitTest.php       |  2 +-
 .../src/Tests/Block/SystemMenuBlockTest.php   |  2 +-
 .../Update/UpdatePathTestBaseFilledTest.php   |  7 ++++
 .../src/Tests/Update/UpdatePostUpdateTest.php |  1 +
 core/modules/system/system.post_update.php    | 35 +++++++++++++++++++
 .../config/install/core.date_format.fancy.yml |  2 --
 .../Views/RelationshipNodeTermDataTest.php    |  4 +--
 .../Tests/Views/TaxonomyIndexTidUiTest.php    |  2 +-
 core/modules/tour/src/Entity/Tour.php         |  2 +-
 core/modules/tour/src/Tests/TourTest.php      |  2 +-
 .../user/src/Tests/Views/AccessRoleTest.php   |  4 +--
 core/modules/views/src/Entity/View.php        |  2 +-
 .../Tests/Entity/FilterEntityBundleTest.php   |  2 +-
 .../Entity/ViewEntityDependenciesTest.php     |  6 ++--
 .../src/Tests/Handler/AreaEntityTest.php      |  2 +-
 .../views/src/Tests/Handler/AreaViewTest.php  |  2 +-
 .../Tests/Plugin/BlockDependenciesTest.php    |  4 +--
 .../src/Tests/Plugin/DisplayPageTest.php      |  6 ++--
 core/modules/views/src/ViewExecutable.php     |  7 ++--
 core/modules/views_ui/src/ViewUI.php          |  2 ++
 .../Entity/ConfigEntityBaseUnitTest.php       | 14 ++++----
 .../Entity/EntityDisplayModeBaseUnitTest.php  |  2 +-
 57 files changed, 149 insertions(+), 101 deletions(-)
 create mode 100644 core/modules/system/system.post_update.php

diff --git a/core/lib/Drupal/Core/Config/ConfigManager.php b/core/lib/Drupal/Core/Config/ConfigManager.php
index eb5949749832..e5b471da6487 100644
--- a/core/lib/Drupal/Core/Config/ConfigManager.php
+++ b/core/lib/Drupal/Core/Config/ConfigManager.php
@@ -320,7 +320,8 @@ public function getConfigEntitiesToChangeOnDependencyRemoval($type, array $names
       }
       if ($this->callOnDependencyRemoval($dependent, $original_dependencies, $type, $names)) {
         // Recalculate dependencies and update the dependency graph data.
-        $dependency_manager->updateData($dependent->getConfigDependencyName(), $dependent->calculateDependencies());
+        $dependent->calculateDependencies();
+        $dependency_manager->updateData($dependent->getConfigDependencyName(), $dependent->getDependencies());
         // Based on the updated data rebuild the list of dependents.
         $dependents = $this->findConfigEntityDependentsAsEntities($type, $names, $dependency_manager);
         // Ensure that the dependency has actually been fixed. It is possible
@@ -458,6 +459,9 @@ public function findMissingContentDependencies() {
       if (isset($config_data['dependencies']['content'])) {
         $content_dependencies = array_merge($content_dependencies, $config_data['dependencies']['content']);
       }
+      if (isset($config_data['dependencies']['enforced']['content'])) {
+        $content_dependencies = array_merge($content_dependencies, $config_data['dependencies']['enforced']['content']);
+      }
     }
     foreach (array_unique($content_dependencies) as $content_dependency) {
       // Format of the dependency is entity_type:bundle:uuid.
diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigDependencyManager.php b/core/lib/Drupal/Core/Config/Entity/ConfigDependencyManager.php
index a762de983db8..80180ce89131 100644
--- a/core/lib/Drupal/Core/Config/Entity/ConfigDependencyManager.php
+++ b/core/lib/Drupal/Core/Config/Entity/ConfigDependencyManager.php
@@ -58,11 +58,11 @@
  * Configuration entity classes usually extend
  * \Drupal\Core\Config\Entity\ConfigEntityBase. The base class provides a
  * generic implementation of the calculateDependencies() method that can
- * discover dependencies due to enforced dependencies, plugins, and third party
- * settings. If the configuration entity has dependencies that cannot be
- * discovered by the base class's implementation, then it needs to implement
+ * discover dependencies due to plugins, and third party settings. If the
+ * configuration entity has dependencies that cannot be discovered by the base
+ * class's implementation, then it needs to implement
  * \Drupal\Core\Config\Entity\ConfigEntityInterface::calculateDependencies() to
- * calculate (and return) the dependencies. In this method, use
+ * calculate the dependencies. In this method, use
  * \Drupal\Core\Config\Entity\ConfigEntityBase::addDependency() to add
  * dependencies. Implementations should call the base class implementation to
  * inherit the generic functionality.
@@ -87,7 +87,7 @@
  * for configuration synchronization, which needs to be able to validate
  * configuration in the staging directory before the synchronization has
  * occurred. Also, if you have a configuration entity object and you want to
- * get the current dependencies without recalculation, you can use
+ * get the current dependencies (without recalculation), you can use
  * \Drupal\Core\Config\Entity\ConfigEntityInterface::getDependencies().
  *
  * When uninstalling a module or a theme, configuration entities that are
@@ -115,6 +115,7 @@
  * module dependency in the sub-module only.
  *
  * @see \Drupal\Core\Config\Entity\ConfigEntityInterface::calculateDependencies()
+ * @see \Drupal\Core\Config\Entity\ConfigEntityInterface::getDependencies()
  * @see \Drupal\Core\Config\Entity\ConfigEntityInterface::onDependencyRemoval()
  * @see \Drupal\Core\Config\Entity\ConfigEntityBase::addDependency()
  * @see \Drupal\Core\Config\ConfigInstallerInterface::installDefaultConfig()
diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php
index d9e1df863f9b..4dd5231e8992 100644
--- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php
+++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php
@@ -7,6 +7,7 @@
 
 namespace Drupal\Core\Config\Entity;
 
+use Drupal\Component\Utility\NestedArray;
 use Drupal\Core\Cache\Cache;
 use Drupal\Core\Config\ConfigException;
 use Drupal\Core\Config\Schema\SchemaIncompleteException;
@@ -353,16 +354,9 @@ public function preSave(EntityStorageInterface $storage) {
    * {@inheritdoc}
    */
   public function calculateDependencies() {
-    // Dependencies should be recalculated on every save. This ensures stale
-    // dependencies are never saved.
-    if (isset($this->dependencies['enforced'])) {
-      $dependencies = $this->dependencies['enforced'];
-      $this->dependencies = $dependencies;
-      $this->dependencies['enforced'] = $dependencies;
-    }
-    else {
-      $this->dependencies = array();
-    }
+    // All dependencies should be recalculated on every save apart from enforced
+    // dependencies. This ensures stale dependencies are never saved.
+    $this->dependencies = array_intersect_key($this->dependencies, ['enforced' => '']);
     if ($this instanceof EntityWithPluginCollectionInterface) {
       // Configuration entities need to depend on the providers of any plugins
       // that they store the configuration for.
@@ -379,7 +373,7 @@ public function calculateDependencies() {
         $this->addDependency('module', $provider);
       }
     }
-    return $this->dependencies;
+    return $this;
   }
 
   /**
@@ -438,7 +432,14 @@ protected function addDependency($type, $name) {
    * {@inheritdoc}
    */
   public function getDependencies() {
-    return $this->dependencies;
+    $dependencies = $this->dependencies;
+    if (isset($dependencies['enforced'])) {
+      // Merge the enforced dependencies into the list of dependencies.
+      $enforced_dependencies = $dependencies['enforced'];
+      unset($dependencies['enforced']);
+      $dependencies = NestedArray::mergeDeep($dependencies, $enforced_dependencies);
+    }
+    return $dependencies;
   }
 
   /**
diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityDependency.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityDependency.php
index 9ca55b67f59f..87e660570c27 100644
--- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityDependency.php
+++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityDependency.php
@@ -7,6 +7,8 @@
 
 namespace Drupal\Core\Config\Entity;
 
+use Drupal\Component\Utility\NestedArray;
+
 /**
  * Provides a value object to discover configuration dependencies.
  *
@@ -26,7 +28,7 @@ class ConfigEntityDependency {
    *
    * @var array
    */
-  protected $dependencies;
+  protected $dependencies = [];
 
   /**
    * Constructs the configuration entity dependency from the entity values.
@@ -36,13 +38,16 @@ class ConfigEntityDependency {
    * @param array $values
    *   (optional) The configuration entity's values.
    */
-  public function __construct($name, $values = array()) {
+  public function __construct($name, $values = []) {
     $this->name = $name;
-    if (isset($values['dependencies'])) {
-      $this->dependencies = $values['dependencies'];
+    if (isset($values['dependencies']) && isset($values['dependencies']['enforced'])) {
+      // Merge the enforced dependencies into the list of dependencies.
+      $enforced_dependencies = $values['dependencies']['enforced'];
+      unset($values['dependencies']['enforced']);
+      $this->dependencies = NestedArray::mergeDeep($values['dependencies'], $enforced_dependencies);
     }
-    else {
-      $this->dependencies = array();
+    elseif (isset($values['dependencies'])) {
+      $this->dependencies = $values['dependencies'];
     }
   }
 
diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityInterface.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityInterface.php
index bd8c48c87df6..766fa6ffe826 100644
--- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityInterface.php
+++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityInterface.php
@@ -144,8 +144,7 @@ public function set($property_name, $value);
   /**
    * Calculates dependencies and stores them in the dependency property.
    *
-   * @return array
-   *   An array of dependencies grouped by type (module, theme, entity).
+   * @return $this
    *
    * @see \Drupal\Core\Config\Entity\ConfigDependencyManager
    */
diff --git a/core/lib/Drupal/Core/Entity/EntityDisplayBase.php b/core/lib/Drupal/Core/Entity/EntityDisplayBase.php
index 2cf18d859d59..b835327b791d 100644
--- a/core/lib/Drupal/Core/Entity/EntityDisplayBase.php
+++ b/core/lib/Drupal/Core/Entity/EntityDisplayBase.php
@@ -278,7 +278,7 @@ public function calculateDependencies() {
       $mode_entity = $this->entityManager()->getStorage('entity_' . $this->displayContext . '_mode')->load($target_entity_type->id() . '.' . $this->mode);
       $this->addDependency('config', $mode_entity->getConfigDependencyName());
     }
-    return $this->dependencies;
+    return $this;
   }
 
   /**
diff --git a/core/lib/Drupal/Core/Entity/EntityDisplayModeBase.php b/core/lib/Drupal/Core/Entity/EntityDisplayModeBase.php
index bc7e7f758d5b..998e1c79eda8 100644
--- a/core/lib/Drupal/Core/Entity/EntityDisplayModeBase.php
+++ b/core/lib/Drupal/Core/Entity/EntityDisplayModeBase.php
@@ -93,7 +93,7 @@ public function calculateDependencies() {
     parent::calculateDependencies();
     $target_entity_type = \Drupal::entityManager()->getDefinition($this->targetEntityType);
     $this->addDependency('module', $target_entity_type->getProvider());
-    return $this->dependencies;
+    return $this;
   }
 
   /**
diff --git a/core/lib/Drupal/Core/Field/FieldConfigBase.php b/core/lib/Drupal/Core/Field/FieldConfigBase.php
index e9fbaca654fc..e3728be01c81 100644
--- a/core/lib/Drupal/Core/Field/FieldConfigBase.php
+++ b/core/lib/Drupal/Core/Field/FieldConfigBase.php
@@ -245,7 +245,7 @@ public function calculateDependencies() {
     $bundle_config_dependency = $this->entityManager()->getDefinition($this->entity_type)->getBundleConfigDependency($this->bundle);
     $this->addDependency($bundle_config_dependency['type'], $bundle_config_dependency['name']);
 
-    return $this->dependencies;
+    return $this;
   }
 
   /**
diff --git a/core/modules/block/src/Entity/Block.php b/core/modules/block/src/Entity/Block.php
index d2b30319962b..8a658438ef04 100644
--- a/core/modules/block/src/Entity/Block.php
+++ b/core/modules/block/src/Entity/Block.php
@@ -231,7 +231,7 @@ public static function sort(ConfigEntityInterface $a, ConfigEntityInterface $b)
   public function calculateDependencies() {
     parent::calculateDependencies();
     $this->addDependency('theme', $this->theme);
-    return $this->dependencies;
+    return $this;
   }
 
   /**
diff --git a/core/modules/block/tests/src/Unit/BlockConfigEntityUnitTest.php b/core/modules/block/tests/src/Unit/BlockConfigEntityUnitTest.php
index c0d6743af78f..39a4e11b4e5c 100644
--- a/core/modules/block/tests/src/Unit/BlockConfigEntityUnitTest.php
+++ b/core/modules/block/tests/src/Unit/BlockConfigEntityUnitTest.php
@@ -100,7 +100,7 @@ public function testCalculateDependencies() {
       ->method('getPluginCollections')
       ->will($this->returnValue(array($plugin_collection)));
 
-    $dependencies = $entity->calculateDependencies();
+    $dependencies = $entity->calculateDependencies()->getDependencies();
     $this->assertContains('test', $dependencies['module']);
     $this->assertContains('stark', $dependencies['theme']);
   }
diff --git a/core/modules/book/config/install/core.entity_view_mode.node.print.yml b/core/modules/book/config/install/core.entity_view_mode.node.print.yml
index 270694929432..d695ac52d74a 100644
--- a/core/modules/book/config/install/core.entity_view_mode.node.print.yml
+++ b/core/modules/book/config/install/core.entity_view_mode.node.print.yml
@@ -2,7 +2,6 @@ langcode: en
 status: false
 dependencies:
   module:
-    - book
     - node
   enforced:
     module:
diff --git a/core/modules/book/config/install/node.type.book.yml b/core/modules/book/config/install/node.type.book.yml
index 531677fd15d0..0d1d0c06b62d 100644
--- a/core/modules/book/config/install/node.type.book.yml
+++ b/core/modules/book/config/install/node.type.book.yml
@@ -1,8 +1,6 @@
 langcode: en
 status: true
 dependencies:
-  module:
-    - book
   enforced:
     module:
       - book
diff --git a/core/modules/config/src/Tests/ConfigDependencyTest.php b/core/modules/config/src/Tests/ConfigDependencyTest.php
index 35b176c71818..050797dae91f 100644
--- a/core/modules/config/src/Tests/ConfigDependencyTest.php
+++ b/core/modules/config/src/Tests/ConfigDependencyTest.php
@@ -69,7 +69,8 @@ public function testDependencyManagement() {
     // Ensure that the provider of the config entity is not actually written to
     // the dependencies array.
     $raw_config = $this->config('config_test.dynamic.entity1');
-    $this->assertTrue(array_search('node', $raw_config->get('dependencies.module')) !== FALSE, 'Node module is written to the dependencies array as this has to be explicit.');
+    $root_module_dependencies = $raw_config->get('dependencies.module');
+    $this->assertTrue(empty($root_module_dependencies), 'Node module is not written to the root dependencies array as it is enforced.');
 
     // Create additional entities to test dependencies on config entities.
     $entity2 = $storage->create(array('id' => 'entity2', 'dependencies' => array('enforced' => array('config' => array($entity1->getConfigDependencyName())))));
@@ -301,10 +302,10 @@ public function testConfigEntityUninstall() {
     $this->assertFalse($storage->load('entity1'), 'Entity 1 deleted');
     $entity2 = $storage->load('entity2');
     $this->assertTrue($entity2, 'Entity 2 not deleted');
-    $this->assertEqual($entity2->calculateDependencies()['config'], array(), 'Entity 2 dependencies updated to remove dependency on Entity1.');
+    $this->assertEqual($entity2->calculateDependencies()->getDependencies()['config'], array(), 'Entity 2 dependencies updated to remove dependency on Entity1.');
     $entity3 = $storage->load('entity3');
     $this->assertTrue($entity3, 'Entity 3 not deleted');
-    $this->assertEqual($entity3->calculateDependencies()['config'], [$entity2->getConfigDependencyName()], 'Entity 3 still depends on Entity 2.');
+    $this->assertEqual($entity3->calculateDependencies()->getDependencies()['config'], [$entity2->getConfigDependencyName()], 'Entity 3 still depends on Entity 2.');
     $this->assertFalse($storage->load('entity4'), 'Entity 4 deleted');
   }
 
@@ -402,10 +403,10 @@ public function testConfigEntityDelete() {
     $this->assertFalse($storage->load('entity1'), 'Entity 1 deleted');
     $entity2 = $storage->load('entity2');
     $this->assertTrue($entity2, 'Entity 2 not deleted');
-    $this->assertEqual($entity2->calculateDependencies()['config'], array(), 'Entity 2 dependencies updated to remove dependency on Entity1.');
+    $this->assertEqual($entity2->calculateDependencies()->getDependencies()['config'], array(), 'Entity 2 dependencies updated to remove dependency on Entity1.');
     $entity3 = $storage->load('entity3');
     $this->assertTrue($entity3, 'Entity 3 not deleted');
-    $this->assertEqual($entity3->calculateDependencies()['config'], [$entity2->getConfigDependencyName()], 'Entity 3 still depends on Entity 2.');
+    $this->assertEqual($entity3->calculateDependencies()->getDependencies()['config'], [$entity2->getConfigDependencyName()], 'Entity 3 still depends on Entity 2.');
   }
 
   /**
diff --git a/core/modules/config/src/Tests/ConfigDependencyWebTest.php b/core/modules/config/src/Tests/ConfigDependencyWebTest.php
index 24d2a1544b35..af63fedc7c13 100644
--- a/core/modules/config/src/Tests/ConfigDependencyWebTest.php
+++ b/core/modules/config/src/Tests/ConfigDependencyWebTest.php
@@ -125,10 +125,10 @@ function testConfigDependencyDeleteFormTrait() {
     $this->assertFalse($storage->load('entity1'), 'Test entity 1 deleted');
     $entity2 = $storage->load('entity2');
     $this->assertTrue($entity2, 'Entity 2 not deleted');
-    $this->assertEqual($entity2->calculateDependencies()['config'], array(), 'Entity 2 dependencies updated to remove dependency on Entity1.');
+    $this->assertEqual($entity2->calculateDependencies()->getDependencies()['config'], array(), 'Entity 2 dependencies updated to remove dependency on Entity1.');
     $entity3 = $storage->load('entity3');
     $this->assertTrue($entity3, 'Entity 3 not deleted');
-    $this->assertEqual($entity3->calculateDependencies()['config'], [$entity2->getConfigDependencyName()], 'Entity 3 still depends on Entity 2.');
+    $this->assertEqual($entity3->calculateDependencies()->getDependencies()['config'], [$entity2->getConfigDependencyName()], 'Entity 3 still depends on Entity 2.');
 
   }
 
diff --git a/core/modules/config/tests/config_other_module_config_test/config/optional/config_test.dynamic.other_module_test_unmet.yml b/core/modules/config/tests/config_other_module_config_test/config/optional/config_test.dynamic.other_module_test_unmet.yml
index 572a79f00dfe..5d788fbe5589 100644
--- a/core/modules/config/tests/config_other_module_config_test/config/optional/config_test.dynamic.other_module_test_unmet.yml
+++ b/core/modules/config/tests/config_other_module_config_test/config/optional/config_test.dynamic.other_module_test_unmet.yml
@@ -6,8 +6,6 @@ status: true
 langcode: en
 protected_property: Default
 dependencies:
-  module:
-    - config_install_dependency_test
   enforced:
     module:
       - config_install_dependency_test
diff --git a/core/modules/editor/src/Entity/Editor.php b/core/modules/editor/src/Entity/Editor.php
index 159c9b13f96c..010067189bc5 100644
--- a/core/modules/editor/src/Entity/Editor.php
+++ b/core/modules/editor/src/Entity/Editor.php
@@ -107,7 +107,7 @@ public function calculateDependencies() {
     //   config entity and dependency on provider is managed automatically.
     $definition = $this->editorPluginManager()->createInstance($this->editor)->getPluginDefinition();
     $this->addDependency('module', $definition['provider']);
-    return $this->dependencies;
+    return $this;
   }
 
   /**
diff --git a/core/modules/editor/tests/src/Unit/EditorConfigEntityUnitTest.php b/core/modules/editor/tests/src/Unit/EditorConfigEntityUnitTest.php
index c5a676b7599f..675054444097 100644
--- a/core/modules/editor/tests/src/Unit/EditorConfigEntityUnitTest.php
+++ b/core/modules/editor/tests/src/Unit/EditorConfigEntityUnitTest.php
@@ -130,7 +130,7 @@ public function testCalculateDependencies() {
                         ->with('filter_format')
                         ->will($this->returnValue($storage));
 
-    $dependencies = $entity->calculateDependencies();
+    $dependencies = $entity->calculateDependencies()->getDependencies();
     $this->assertContains('test_module', $dependencies['module']);
     $this->assertContains('filter.format.test', $dependencies['config']);
   }
diff --git a/core/modules/field/src/Entity/FieldConfig.php b/core/modules/field/src/Entity/FieldConfig.php
index 1493e41fcd71..e2ab409fcf01 100644
--- a/core/modules/field/src/Entity/FieldConfig.php
+++ b/core/modules/field/src/Entity/FieldConfig.php
@@ -187,7 +187,7 @@ public function calculateDependencies() {
     parent::calculateDependencies();
     // Mark the field_storage_config as a a dependency.
     $this->addDependency('config', $this->getFieldStorageDefinition()->getConfigDependencyName());
-    return $this->dependencies;
+    return $this;
   }
 
   /**
diff --git a/core/modules/field/src/Entity/FieldStorageConfig.php b/core/modules/field/src/Entity/FieldStorageConfig.php
index bd546a246d60..594fb3b7f7b6 100644
--- a/core/modules/field/src/Entity/FieldStorageConfig.php
+++ b/core/modules/field/src/Entity/FieldStorageConfig.php
@@ -346,7 +346,7 @@ public function calculateDependencies() {
     // Ensure the field is dependent on the provider of the entity type.
     $entity_type = \Drupal::entityManager()->getDefinition($this->entity_type);
     $this->addDependency('module', $entity_type->getProvider());
-    return $this->dependencies;
+    return $this;
   }
 
   /**
diff --git a/core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php b/core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php
index 72cfd764f2d5..4cf0065435a1 100644
--- a/core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php
+++ b/core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php
@@ -153,7 +153,7 @@ public function testCalculateDependencies() {
       'bundle' => 'test_bundle',
       'field_type' => 'test_field',
     ), $this->entityTypeId);
-    $dependencies = $field->calculateDependencies();
+    $dependencies = $field->calculateDependencies()->getDependencies();
     $this->assertContains('field.storage.test_entity_type.test_field', $dependencies['config']);
     $this->assertContains('test.test_entity_type.id', $dependencies['config']);
     $this->assertEquals(['test_module', 'test_module2', 'test_module3'], $dependencies['module']);
diff --git a/core/modules/field/tests/src/Unit/FieldStorageConfigEntityUnitTest.php b/core/modules/field/tests/src/Unit/FieldStorageConfigEntityUnitTest.php
index 424424a7bd5a..ab5fa75e1a86 100644
--- a/core/modules/field/tests/src/Unit/FieldStorageConfigEntityUnitTest.php
+++ b/core/modules/field/tests/src/Unit/FieldStorageConfigEntityUnitTest.php
@@ -93,7 +93,7 @@ public function testCalculateDependencies() {
       'module' => 'test_module',
     ));
 
-    $dependencies = $field_storage->calculateDependencies();
+    $dependencies = $field_storage->calculateDependencies()->getDependencies();
     $this->assertContains('test_module', $dependencies['module']);
     $this->assertContains('entity_provider_module', $dependencies['module']);
   }
diff --git a/core/modules/field_ui/src/Tests/EntityDisplayTest.php b/core/modules/field_ui/src/Tests/EntityDisplayTest.php
index 0cafbb48e287..7c7a48bd4a02 100644
--- a/core/modules/field_ui/src/Tests/EntityDisplayTest.php
+++ b/core/modules/field_ui/src/Tests/EntityDisplayTest.php
@@ -109,7 +109,7 @@ public function testEntityDisplayCRUD() {
     $new_display = $display->createCopy('other_view_mode');
     $new_display->save();
     $new_display = entity_load('entity_view_display', $new_display->id());
-    $dependencies = $new_display->calculateDependencies();
+    $dependencies = $new_display->calculateDependencies()->getDependencies();
     $this->assertEqual(array('config' => array('core.entity_view_mode.entity_test.other_view_mode'), 'module' => array('entity_test')), $dependencies);
     $this->assertEqual($new_display->getTargetEntityTypeId(), $display->getTargetEntityTypeId());
     $this->assertEqual($new_display->getTargetBundle(), $display->getTargetBundle());
@@ -239,7 +239,7 @@ public function testFieldComponent() {
 
     // Check that the display has dependencies on the field and the module that
     // provides the formatter.
-    $dependencies = $display->calculateDependencies();
+    $dependencies = $display->calculateDependencies()->getDependencies();
     $this->assertEqual(array('config' => array('field.field.entity_test.entity_test.test_field'), 'module' => array('entity_test', 'field_test')), $dependencies);
   }
 
diff --git a/core/modules/field_ui/src/Tests/ManageDisplayTest.php b/core/modules/field_ui/src/Tests/ManageDisplayTest.php
index 10bf706f709c..d51f4f387eb7 100644
--- a/core/modules/field_ui/src/Tests/ManageDisplayTest.php
+++ b/core/modules/field_ui/src/Tests/ManageDisplayTest.php
@@ -142,7 +142,7 @@ function testFormatterUI() {
     \Drupal::entityManager()->clearCachedFieldDefinitions();
     $display = entity_load('entity_view_display', 'node.' . $this->type . '.default', TRUE);
     $this->assertEqual($display->getRenderer('field_test')->getThirdPartySetting('field_third_party_test', 'field_test_field_formatter_third_party_settings_form'), 'foo');
-    $this->assertTrue(in_array('field_third_party_test', $display->calculateDependencies()['module']), 'The display has a dependency on field_third_party_test module.');
+    $this->assertTrue(in_array('field_third_party_test', $display->calculateDependencies()->getDependencies()['module']), 'The display has a dependency on field_third_party_test module.');
 
     // Confirm that the third party settings are not updated on the settings form.
     $this->drupalPostAjaxForm(NULL, array(), "field_test_settings_edit");
@@ -268,7 +268,7 @@ public function testWidgetUI() {
     \Drupal::entityManager()->clearCachedFieldDefinitions();
     $display = entity_load('entity_form_display', 'node.' . $this->type . '.default', TRUE);
     $this->assertEqual($display->getRenderer('field_test')->getThirdPartySetting('field_third_party_test', 'field_test_widget_third_party_settings_form'), 'foo');
-    $this->assertTrue(in_array('field_third_party_test', $display->calculateDependencies()['module']), 'Form display does not have a dependency on field_third_party_test module.');
+    $this->assertTrue(in_array('field_third_party_test', $display->calculateDependencies()->getDependencies()['module']), 'Form display does not have a dependency on field_third_party_test module.');
 
     // Confirm that the third party settings are not updated on the settings form.
     $this->drupalPostAjaxForm(NULL, array(), "field_test_settings_edit");
diff --git a/core/modules/file/src/Tests/Views/RelationshipUserFileDataTest.php b/core/modules/file/src/Tests/Views/RelationshipUserFileDataTest.php
index beab748d2a83..8cdc9033d088 100644
--- a/core/modules/file/src/Tests/Views/RelationshipUserFileDataTest.php
+++ b/core/modules/file/src/Tests/Views/RelationshipUserFileDataTest.php
@@ -84,7 +84,7 @@ public function testViewsHandlerRelationshipUserFileData() {
         'user',
       ],
     ];
-    $this->assertIdentical($expected, $view->calculateDependencies());
+    $this->assertIdentical($expected, $view->getDependencies());
     $this->executeView($view);
     $expected_result = array(
       array(
diff --git a/core/modules/forum/config/install/node.type.forum.yml b/core/modules/forum/config/install/node.type.forum.yml
index b03afe0d023d..8ed965df3fb6 100644
--- a/core/modules/forum/config/install/node.type.forum.yml
+++ b/core/modules/forum/config/install/node.type.forum.yml
@@ -1,8 +1,6 @@
 langcode: en
 status: true
 dependencies:
-  module:
-    - forum
   enforced:
     module:
       - forum
diff --git a/core/modules/forum/config/install/taxonomy.vocabulary.forums.yml b/core/modules/forum/config/install/taxonomy.vocabulary.forums.yml
index 311f6fca6a0e..b5c51eb61eac 100644
--- a/core/modules/forum/config/install/taxonomy.vocabulary.forums.yml
+++ b/core/modules/forum/config/install/taxonomy.vocabulary.forums.yml
@@ -1,8 +1,6 @@
 langcode: en
 status: true
 dependencies:
-  module:
-    - forum
   enforced:
     module:
       - forum
diff --git a/core/modules/image/src/Tests/Views/RelationshipUserImageDataTest.php b/core/modules/image/src/Tests/Views/RelationshipUserImageDataTest.php
index a36f287bfe0d..4ef06269ecfe 100644
--- a/core/modules/image/src/Tests/Views/RelationshipUserImageDataTest.php
+++ b/core/modules/image/src/Tests/Views/RelationshipUserImageDataTest.php
@@ -84,7 +84,7 @@ public function testViewsHandlerRelationshipUserImageData() {
         'user',
       ],
     ];
-    $this->assertIdentical($expected, $view->calculateDependencies());
+    $this->assertIdentical($expected, $view->getDependencies());
     $this->executeView($view);
     $expected_result = array(
       array(
diff --git a/core/modules/language/src/Entity/ContentLanguageSettings.php b/core/modules/language/src/Entity/ContentLanguageSettings.php
index 75049985c64a..7501012010cb 100644
--- a/core/modules/language/src/Entity/ContentLanguageSettings.php
+++ b/core/modules/language/src/Entity/ContentLanguageSettings.php
@@ -200,7 +200,7 @@ public function calculateDependencies() {
     $bundle_config_dependency = $entity_type->getBundleConfigDependency($this->target_bundle);
     $this->addDependency($bundle_config_dependency['type'], $bundle_config_dependency['name']);
 
-    return $this->dependencies;
+    return $this;
   }
 
 }
diff --git a/core/modules/language/tests/src/Unit/ContentLanguageSettingsUnitTest.php b/core/modules/language/tests/src/Unit/ContentLanguageSettingsUnitTest.php
index 04ab81b43c2e..af73b75cabc1 100644
--- a/core/modules/language/tests/src/Unit/ContentLanguageSettingsUnitTest.php
+++ b/core/modules/language/tests/src/Unit/ContentLanguageSettingsUnitTest.php
@@ -102,7 +102,7 @@ public function testCalculateDependencies() {
       'target_entity_type_id' => 'test_entity_type',
       'target_bundle' => 'test_bundle',
     ), 'language_content_settings');
-    $dependencies = $config->calculateDependencies();
+    $dependencies = $config->calculateDependencies()->getDependencies();
     $this->assertContains('test.test_entity_type.id', $dependencies['config']);
   }
 
diff --git a/core/modules/migrate/src/Entity/Migration.php b/core/modules/migrate/src/Entity/Migration.php
index b79a00da5805..0d7e3c81f606 100644
--- a/core/modules/migrate/src/Entity/Migration.php
+++ b/core/modules/migrate/src/Entity/Migration.php
@@ -590,6 +590,6 @@ public function calculateDependencies() {
       $this->addDependency('config', $this->getEntityType()->getConfigPrefix() . '.' . $dependency);
     }
 
-    return $this->dependencies;
+    return $this;
   }
 }
diff --git a/core/modules/node/src/Tests/Views/FrontPageTest.php b/core/modules/node/src/Tests/Views/FrontPageTest.php
index ba8438f23ca4..5cd78a8f9fcc 100644
--- a/core/modules/node/src/Tests/Views/FrontPageTest.php
+++ b/core/modules/node/src/Tests/Views/FrontPageTest.php
@@ -73,7 +73,7 @@ public function testFrontPage() {
         'user',
       ],
     ];
-    $this->assertIdentical($expected, $view->calculateDependencies());
+    $this->assertIdentical($expected, $view->getDependencies());
 
     $view->setDisplay('page_1');
     $this->executeView($view);
diff --git a/core/modules/rdf/src/Entity/RdfMapping.php b/core/modules/rdf/src/Entity/RdfMapping.php
index c260f14c72f9..f561f15ac34e 100644
--- a/core/modules/rdf/src/Entity/RdfMapping.php
+++ b/core/modules/rdf/src/Entity/RdfMapping.php
@@ -148,7 +148,7 @@ public function calculateDependencies() {
     $bundle_config_dependency = $entity_type->getBundleConfigDependency($this->bundle);
     $this->addDependency($bundle_config_dependency['type'], $bundle_config_dependency['name']);
 
-    return $this->dependencies;
+    return $this;
   }
 
   /**
diff --git a/core/modules/rdf/tests/src/Unit/RdfMappingConfigEntityUnitTest.php b/core/modules/rdf/tests/src/Unit/RdfMappingConfigEntityUnitTest.php
index 4901d9cc716b..a3198e9f5170 100644
--- a/core/modules/rdf/tests/src/Unit/RdfMappingConfigEntityUnitTest.php
+++ b/core/modules/rdf/tests/src/Unit/RdfMappingConfigEntityUnitTest.php
@@ -92,7 +92,7 @@ public function testCalculateDependencies() {
       ->will($this->returnValue($this->entityType));
 
     $entity = new RdfMapping($values, $this->entityTypeId);
-    $dependencies = $entity->calculateDependencies();
+    $dependencies = $entity->calculateDependencies()->getDependencies();
     $this->assertArrayNotHasKey('config', $dependencies);
     $this->assertContains('test_module', $dependencies['module']);
   }
@@ -123,7 +123,7 @@ public function testCalculateDependenciesWithEntityBundle() {
                         ->will($this->returnValue($this->entityType));
 
     $entity = new RdfMapping($values, $this->entityTypeId);
-    $dependencies = $entity->calculateDependencies();
+    $dependencies = $entity->calculateDependencies()->getDependencies();
     $this->assertContains('test_module.type.' . $bundle_id, $dependencies['config']);
     $this->assertContains('test_module', $dependencies['module']);
   }
diff --git a/core/modules/responsive_image/src/Entity/ResponsiveImageStyle.php b/core/modules/responsive_image/src/Entity/ResponsiveImageStyle.php
index f585bc240a38..e82b57fc245f 100644
--- a/core/modules/responsive_image/src/Entity/ResponsiveImageStyle.php
+++ b/core/modules/responsive_image/src/Entity/ResponsiveImageStyle.php
@@ -212,7 +212,7 @@ public function calculateDependencies() {
     array_walk($styles, function ($style) {
       $this->addDependency('config', $style->getConfigDependencyName());
     });
-    return $this->dependencies;
+    return $this;
   }
 
   /**
diff --git a/core/modules/responsive_image/tests/src/Unit/ResponsiveImageStyleConfigEntityUnitTest.php b/core/modules/responsive_image/tests/src/Unit/ResponsiveImageStyleConfigEntityUnitTest.php
index c9167565b1d5..5e33a31a0385 100644
--- a/core/modules/responsive_image/tests/src/Unit/ResponsiveImageStyleConfigEntityUnitTest.php
+++ b/core/modules/responsive_image/tests/src/Unit/ResponsiveImageStyleConfigEntityUnitTest.php
@@ -108,7 +108,7 @@ public function testCalculateDependencies() {
       ->with('test_group')
       ->willReturn(array('bartik' => 'theme', 'toolbar' => 'module'));
 
-    $dependencies = $entity->calculateDependencies();
+    $dependencies = $entity->calculateDependencies()->getDependencies();
     $this->assertEquals(['toolbar'], $dependencies['module']);
     $this->assertEquals(['bartik'], $dependencies['theme']);
     $this->assertEquals(['image.style.fallback', 'image.style.large', 'image.style.medium', 'image.style.small'], $dependencies['config']);
diff --git a/core/modules/system/src/Tests/Action/ActionUnitTest.php b/core/modules/system/src/Tests/Action/ActionUnitTest.php
index 164b562320e1..7bc57b594f48 100644
--- a/core/modules/system/src/Tests/Action/ActionUnitTest.php
+++ b/core/modules/system/src/Tests/Action/ActionUnitTest.php
@@ -99,7 +99,7 @@ public function testDependencies() {
         'user',
       ),
     );
-    $this->assertIdentical($expected, $action->calculateDependencies());
+    $this->assertIdentical($expected, $action->calculateDependencies()->getDependencies());
   }
 
 }
diff --git a/core/modules/system/src/Tests/Block/SystemMenuBlockTest.php b/core/modules/system/src/Tests/Block/SystemMenuBlockTest.php
index a28b696b5a83..25e5dc1f6545 100644
--- a/core/modules/system/src/Tests/Block/SystemMenuBlockTest.php
+++ b/core/modules/system/src/Tests/Block/SystemMenuBlockTest.php
@@ -162,7 +162,7 @@ public function testSystemMenuBlockConfigDependencies() {
       'theme' => 'stark',
     ));
 
-    $dependencies = $block->calculateDependencies();
+    $dependencies = $block->calculateDependencies()->getDependencies();
     $expected = array(
       'config' => array(
         'system.menu.' . $this->menu->id()
diff --git a/core/modules/system/src/Tests/Update/UpdatePathTestBaseFilledTest.php b/core/modules/system/src/Tests/Update/UpdatePathTestBaseFilledTest.php
index 4ccc6e7c4ba9..4dceb5dd908c 100644
--- a/core/modules/system/src/Tests/Update/UpdatePathTestBaseFilledTest.php
+++ b/core/modules/system/src/Tests/Update/UpdatePathTestBaseFilledTest.php
@@ -8,6 +8,7 @@
 namespace Drupal\system\Tests\Update;
 
 use Drupal\node\Entity\Node;
+use Drupal\node\Entity\NodeType;
 use Drupal\user\Entity\User;
 
 /**
@@ -415,6 +416,12 @@ public function testUpdatedSite() {
     foreach ($expected_enabled_themes as $theme) {
       $this->assertTrue($this->container->get('theme_handler')->themeExists($theme), 'The "' . $theme . '" is still enabled.');
     }
+
+    // Ensure that the Book module's node type does not have duplicated enforced
+    // dependencies.
+    // @see system_post_update_fix_enforced_dependencies()
+    $book_node_type = NodeType::load('book');
+    $this->assertEqual(['enforced' => ['module' => ['book']]], $book_node_type->get('dependencies'));
   }
 
   /**
diff --git a/core/modules/system/src/Tests/Update/UpdatePostUpdateTest.php b/core/modules/system/src/Tests/Update/UpdatePostUpdateTest.php
index a295268d3bea..55420fae8f7c 100644
--- a/core/modules/system/src/Tests/Update/UpdatePostUpdateTest.php
+++ b/core/modules/system/src/Tests/Update/UpdatePostUpdateTest.php
@@ -62,6 +62,7 @@ public function testPostUpdate() {
     $updates = array_merge([
       'block_post_update_disable_blocks_with_missing_contexts',
       'field_post_update_save_custom_storage_property',
+      'system_post_update_fix_enforced_dependencies',
       'views_post_update_update_cacheability_metadata',
     ], $updates);
     $this->assertEqual($updates, $key_value->get('existing_updates'));
diff --git a/core/modules/system/system.post_update.php b/core/modules/system/system.post_update.php
new file mode 100644
index 000000000000..3a141cee232e
--- /dev/null
+++ b/core/modules/system/system.post_update.php
@@ -0,0 +1,35 @@
+<?php
+
+/**
+ * @file
+ * Post update functions for System.
+ */
+
+/**
+ * @addtogroup updates-8.0.0-beta
+ * @{
+ */
+
+/**
+ * Re-save all config objects with enforced dependencies.
+ */
+function system_post_update_fix_enforced_dependencies() {
+  $config_factory = \Drupal::configFactory();
+  /** @var \Drupal\Core\Config\ConfigManagerInterface $config_manager */
+  $config_manager = \Drupal::service('config.manager');
+  // Iterate on all configuration entities.
+  foreach ($config_factory->listAll() as $id) {
+    $config = $config_factory->get($id);
+    if ($config->get('dependencies.enforced') !== NULL) {
+      // Resave the configuration entity.
+      $entity = $config_manager->loadConfigEntityByName($id);
+      $entity->save();
+    }
+  }
+
+  return t('All configuration objects with enforced dependencies re-saved.');
+}
+
+/**
+ * @} End of "addtogroup updates-8.0.0-beta".
+ */
diff --git a/core/modules/system/tests/themes/test_basetheme/config/install/core.date_format.fancy.yml b/core/modules/system/tests/themes/test_basetheme/config/install/core.date_format.fancy.yml
index cdab20542650..2b962d65faf2 100644
--- a/core/modules/system/tests/themes/test_basetheme/config/install/core.date_format.fancy.yml
+++ b/core/modules/system/tests/themes/test_basetheme/config/install/core.date_format.fancy.yml
@@ -8,8 +8,6 @@ langcode: en
 locked: false
 pattern: 'U'
 dependencies:
-  theme:
-    - test_basetheme
   enforced:
     theme:
       - test_basetheme
diff --git a/core/modules/taxonomy/src/Tests/Views/RelationshipNodeTermDataTest.php b/core/modules/taxonomy/src/Tests/Views/RelationshipNodeTermDataTest.php
index eed681f830dc..68a2afb01d1c 100644
--- a/core/modules/taxonomy/src/Tests/Views/RelationshipNodeTermDataTest.php
+++ b/core/modules/taxonomy/src/Tests/Views/RelationshipNodeTermDataTest.php
@@ -34,7 +34,7 @@ function testViewsHandlerRelationshipNodeTermData() {
         'user',
       ],
     ];
-    $this->assertIdentical($expected, $view->calculateDependencies());
+    $this->assertIdentical($expected, $view->getDependencies());
     $this->executeView($view, array($this->term1->id(), $this->term2->id()));
     $expected_result = array(
       array(
@@ -55,7 +55,7 @@ function testViewsHandlerRelationshipNodeTermData() {
     $view = Views::getView('test_taxonomy_node_term_data');
     // Tests \Drupal\taxonomy\Plugin\views\relationship\NodeTermData::calculateDependencies().
     $expected['config'][] = 'taxonomy.vocabulary.views_testing_tags';
-    $this->assertIdentical($expected, $view->calculateDependencies());
+    $this->assertIdentical($expected, $view->getDependencies());
     $this->executeView($view, array($this->term1->id(), $this->term2->id()));
     $this->assertIdenticalResultset($view, $expected_result, $column_map);
   }
diff --git a/core/modules/taxonomy/src/Tests/Views/TaxonomyIndexTidUiTest.php b/core/modules/taxonomy/src/Tests/Views/TaxonomyIndexTidUiTest.php
index 4ea9e3240cb6..c32f27c24415 100644
--- a/core/modules/taxonomy/src/Tests/Views/TaxonomyIndexTidUiTest.php
+++ b/core/modules/taxonomy/src/Tests/Views/TaxonomyIndexTidUiTest.php
@@ -121,7 +121,7 @@ public function testFilterUI() {
         'user',
       ],
     ];
-    $this->assertIdentical($expected, $view->calculateDependencies());
+    $this->assertIdentical($expected, $view->calculateDependencies()->getDependencies());
   }
 
   /**
diff --git a/core/modules/tour/src/Entity/Tour.php b/core/modules/tour/src/Entity/Tour.php
index 72540e0efde3..8a4576c7d936 100644
--- a/core/modules/tour/src/Entity/Tour.php
+++ b/core/modules/tour/src/Entity/Tour.php
@@ -183,7 +183,7 @@ public function calculateDependencies() {
     }
 
     $this->addDependency('module', $this->module);
-    return $this->dependencies;
+    return $this;
   }
 
 }
diff --git a/core/modules/tour/src/Tests/TourTest.php b/core/modules/tour/src/Tests/TourTest.php
index d0acf458e041..7f656d3abca9 100644
--- a/core/modules/tour/src/Tests/TourTest.php
+++ b/core/modules/tour/src/Tests/TourTest.php
@@ -143,7 +143,7 @@ public function testTourFunctionality() {
 
     // Ensure that a tour entity has the expected dependencies based on plugin
     // providers and the module named in the configuration entity.
-    $dependencies = $tour->calculateDependencies();
+    $dependencies = $tour->calculateDependencies()->getDependencies();
     $this->assertEqual($dependencies['module'], array('system', 'tour_test'));
 
     $this->drupalGet('tour-test-1');
diff --git a/core/modules/user/src/Tests/Views/AccessRoleTest.php b/core/modules/user/src/Tests/Views/AccessRoleTest.php
index 6960bc5faaca..043971a260ef 100644
--- a/core/modules/user/src/Tests/Views/AccessRoleTest.php
+++ b/core/modules/user/src/Tests/Views/AccessRoleTest.php
@@ -44,7 +44,7 @@ function testAccessRole() {
       'config' => ['user.role.' . $this->normalRole],
       'module' => ['user'],
     ];
-    $this->assertIdentical($expected, $view->calculateDependencies());
+    $this->assertIdentical($expected, $view->calculateDependencies()->getDependencies());
 
     $executable = Views::executableFactory()->get($view);
     $executable->setDisplay('page_1');
@@ -84,7 +84,7 @@ function testAccessRole() {
       'config' => $roles,
       'module' => ['user'],
     ];
-    $this->assertIdentical($expected, $view->calculateDependencies());
+    $this->assertIdentical($expected, $view->calculateDependencies()->getDependencies());
     $this->drupalLogin($this->webUser);
     $this->drupalGet('test-role');
     $this->assertResponse(403);
diff --git a/core/modules/views/src/Entity/View.php b/core/modules/views/src/Entity/View.php
index 775efdb8cf47..e2a3436f3f03 100644
--- a/core/modules/views/src/Entity/View.php
+++ b/core/modules/views/src/Entity/View.php
@@ -286,7 +286,7 @@ public function calculateDependencies() {
       $this->calculatePluginDependencies($display);
     }
 
-    return $this->dependencies;
+    return $this;
   }
 
   /**
diff --git a/core/modules/views/src/Tests/Entity/FilterEntityBundleTest.php b/core/modules/views/src/Tests/Entity/FilterEntityBundleTest.php
index 9be30df02779..709dd37f2b21 100644
--- a/core/modules/views/src/Tests/Entity/FilterEntityBundleTest.php
+++ b/core/modules/views/src/Tests/Entity/FilterEntityBundleTest.php
@@ -84,7 +84,7 @@ public function testFilterEntity() {
         'node'
       ],
     ];
-    $this->assertIdentical($expected, $view->calculateDependencies());
+    $this->assertIdentical($expected, $view->getDependencies());
 
     $this->executeView($view);
 
diff --git a/core/modules/views/src/Tests/Entity/ViewEntityDependenciesTest.php b/core/modules/views/src/Tests/Entity/ViewEntityDependenciesTest.php
index e8a7c1bd661a..5a3f3591e72a 100644
--- a/core/modules/views/src/Tests/Entity/ViewEntityDependenciesTest.php
+++ b/core/modules/views/src/Tests/Entity/ViewEntityDependenciesTest.php
@@ -83,9 +83,9 @@ protected function setUp() {
   }
 
   /**
-   * Tests the calculateDependencies method.
+   * Tests the getDependencies method.
    */
-  public function testCalculateDependencies() {
+  public function testGetDependencies() {
     $expected = [];
     $expected['test_field_get_entity'] = [
       'module' => [
@@ -135,7 +135,7 @@ public function testCalculateDependencies() {
     foreach ($this::$testViews as $view_id) {
       $view = Views::getView($view_id);
 
-      $dependencies = $view->calculateDependencies();
+      $dependencies = $view->getDependencies();
       $this->assertEqual($expected[$view_id], $dependencies);
       $config = $this->config('views.view.' . $view_id);
       \Drupal::service('config.storage.staging')->write($view_id, $config->get());
diff --git a/core/modules/views/src/Tests/Handler/AreaEntityTest.php b/core/modules/views/src/Tests/Handler/AreaEntityTest.php
index ff1f83f4257f..434463b4df63 100644
--- a/core/modules/views/src/Tests/Handler/AreaEntityTest.php
+++ b/core/modules/views/src/Tests/Handler/AreaEntityTest.php
@@ -191,7 +191,7 @@ public function doTestRender($entities) {
   public function doTestCalculateDependencies() {
     $view = View::load('test_entity_area');
 
-    $dependencies = $view->calculateDependencies();
+    $dependencies = $view->calculateDependencies()->getDependencies();
     // Ensure that both config and content entity dependencies are calculated.
     $this->assertEqual([
       'config' => ['block.block.test_block'],
diff --git a/core/modules/views/src/Tests/Handler/AreaViewTest.php b/core/modules/views/src/Tests/Handler/AreaViewTest.php
index f228937ae2f3..779b7957b243 100644
--- a/core/modules/views/src/Tests/Handler/AreaViewTest.php
+++ b/core/modules/views/src/Tests/Handler/AreaViewTest.php
@@ -41,7 +41,7 @@ public function testViewArea() {
     $view = Views::getView('test_area_view');
 
     // Tests \Drupal\views\Plugin\views\area\View::calculateDependencies().
-    $this->assertIdentical(['config' => ['views.view.test_simple_argument']], $view->calculateDependencies());
+    $this->assertIdentical(['config' => ['views.view.test_simple_argument']], $view->getDependencies());
 
     $this->executeView($view);
     $output = $view->render();
diff --git a/core/modules/views/src/Tests/Plugin/BlockDependenciesTest.php b/core/modules/views/src/Tests/Plugin/BlockDependenciesTest.php
index 71e278fc6d36..6a5064cf652f 100644
--- a/core/modules/views/src/Tests/Plugin/BlockDependenciesTest.php
+++ b/core/modules/views/src/Tests/Plugin/BlockDependenciesTest.php
@@ -37,7 +37,7 @@ class BlockDependenciesTest extends ViewKernelTestBase {
    */
   public function testExposedBlock() {
     $block = $this->createBlock('views_exposed_filter_block:test_exposed_block-page_1');
-    $dependencies = $block->calculateDependencies();
+    $dependencies = $block->calculateDependencies()->getDependencies();
     $expected = array(
       'config' => array('views.view.test_exposed_block'),
       'module' => array('views'),
@@ -53,7 +53,7 @@ public function testExposedBlock() {
    */
   public function testViewsBlock() {
     $block = $this->createBlock('views_block:content_recent-block_1');
-    $dependencies = $block->calculateDependencies();
+    $dependencies = $block->calculateDependencies()->getDependencies();
     $expected = array(
       'config' => array('views.view.content_recent'),
       'module' => array('views'),
diff --git a/core/modules/views/src/Tests/Plugin/DisplayPageTest.php b/core/modules/views/src/Tests/Plugin/DisplayPageTest.php
index 6fc4f144cce2..d04d95125994 100644
--- a/core/modules/views/src/Tests/Plugin/DisplayPageTest.php
+++ b/core/modules/views/src/Tests/Plugin/DisplayPageTest.php
@@ -144,14 +144,14 @@ public function testMenuLinks() {
    */
   public function testDependencies() {
     $view = Views::getView('test_page_display');
-    $this->assertIdentical([], $view->calculateDependencies());
+    $this->assertIdentical([], $view->getDependencies());
 
     $view = Views::getView('test_page_display_route');
     $expected = [
       'content' => ['StaticTest'],
       'module' => ['views_test_data'],
     ];
-    $this->assertIdentical($expected, $view->calculateDependencies());
+    $this->assertIdentical($expected, $view->getDependencies());
 
     $view = Views::getView('test_page_display_menu');
     $expected = [
@@ -160,7 +160,7 @@ public function testDependencies() {
         'system.menu.tools',
       ],
     ];
-    $this->assertIdentical($expected, $view->calculateDependencies());
+    $this->assertIdentical($expected, $view->getDependencies());
   }
 
 }
diff --git a/core/modules/views/src/ViewExecutable.php b/core/modules/views/src/ViewExecutable.php
index d64bb28af4b4..d2d1fa575e71 100644
--- a/core/modules/views/src/ViewExecutable.php
+++ b/core/modules/views/src/ViewExecutable.php
@@ -2315,15 +2315,16 @@ public function hasFormElements() {
   }
 
   /**
-   * Calculates dependencies for the view.
+   * Gets dependencies for the view.
    *
    * @see \Drupal\views\Entity\View::calculateDependencies()
+   * @see \Drupal\views\Entity\View::getDependencies()
    *
    * @return array
    *   An array of dependencies grouped by type (module, theme, entity).
    */
-  public function calculateDependencies() {
-    return $this->storage->calculateDependencies();
+  public function getDependencies() {
+    return $this->storage->calculateDependencies()->getDependencies();
   }
 
   /**
diff --git a/core/modules/views_ui/src/ViewUI.php b/core/modules/views_ui/src/ViewUI.php
index 8168bf22802b..75c54731ec09 100644
--- a/core/modules/views_ui/src/ViewUI.php
+++ b/core/modules/views_ui/src/ViewUI.php
@@ -1206,6 +1206,8 @@ public function hasLinkTemplate($key) {
    * {@inheritdoc}
    */
   public function calculateDependencies() {
+    $this->storage->calculateDependencies();
+    return $this;
   }
 
   /**
diff --git a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php
index fa1c006a2642..feca9e93e2ba 100644
--- a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php
+++ b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php
@@ -139,19 +139,19 @@ protected function setUp() {
 
   /**
    * @covers ::calculateDependencies
+   * @covers ::getDependencies
    */
   public function testCalculateDependencies() {
     // Calculating dependencies will reset the dependencies array.
     $this->entity->set('dependencies', array('module' => array('node')));
-    $this->assertEmpty($this->entity->calculateDependencies());
+    $this->assertEmpty($this->entity->calculateDependencies()->getDependencies());
 
     // Calculating dependencies will reset the dependencies array using enforced
     // dependencies.
     $this->entity->set('dependencies', array('module' => array('node'), 'enforced' => array('module' => 'views')));
-    $dependencies = $this->entity->calculateDependencies();
+    $dependencies = $this->entity->calculateDependencies()->getDependencies();
     $this->assertContains('views', $dependencies['module']);
     $this->assertNotContains('node', $dependencies['module']);
-    $this->assertContains('views', $dependencies['enforced']['module']);
   }
 
   /**
@@ -213,6 +213,7 @@ public function testAddDependency() {
   }
 
   /**
+   * @covers ::getDependencies
    * @covers ::calculateDependencies
    *
    * @dataProvider providerCalculateDependenciesWithPluginCollections
@@ -244,7 +245,7 @@ public function testCalculateDependenciesWithPluginCollections($definition, $exp
       ->method('getPluginCollections')
       ->will($this->returnValue(array($pluginCollection)));
 
-    $this->assertEquals($expected_dependencies, $this->entity->calculateDependencies());
+    $this->assertEquals($expected_dependencies, $this->entity->calculateDependencies()->getDependencies());
   }
 
   /**
@@ -289,6 +290,7 @@ public function providerCalculateDependenciesWithPluginCollections() {
 
   /**
    * @covers ::calculateDependencies
+   * @covers ::getDependencies
    * @covers ::onDependencyRemoval
    */
   public function testCalculateDependenciesWithThirdPartySettings() {
@@ -297,12 +299,12 @@ public function testCalculateDependenciesWithThirdPartySettings() {
     $this->entity->setThirdPartySetting('test_provider2', 'test', 'test');
     $this->entity->setThirdPartySetting($this->provider, 'test', 'test');
 
-    $this->assertEquals(array('test_provider', 'test_provider2'), $this->entity->calculateDependencies()['module']);
+    $this->assertEquals(array('test_provider', 'test_provider2'), $this->entity->calculateDependencies()->getDependencies()['module']);
     $changed = $this->entity->onDependencyRemoval(['module' => ['test_provider2']]);
     $this->assertTrue($changed, 'Calling onDependencyRemoval with an existing third party dependency provider returns TRUE.');
     $changed = $this->entity->onDependencyRemoval(['module' => ['test_provider3']]);
     $this->assertFalse($changed, 'Calling onDependencyRemoval with a non-existing third party dependency provider returns FALSE.');
-    $this->assertEquals(array('test_provider'), $this->entity->calculateDependencies()['module']);
+    $this->assertEquals(array('test_provider'), $this->entity->calculateDependencies()->getDependencies()['module']);
   }
 
   /**
diff --git a/core/tests/Drupal/Tests/Core/Config/Entity/EntityDisplayModeBaseUnitTest.php b/core/tests/Drupal/Tests/Core/Config/Entity/EntityDisplayModeBaseUnitTest.php
index 67db1342aafa..1476f6fedb62 100644
--- a/core/tests/Drupal/Tests/Core/Config/Entity/EntityDisplayModeBaseUnitTest.php
+++ b/core/tests/Drupal/Tests/Core/Config/Entity/EntityDisplayModeBaseUnitTest.php
@@ -98,7 +98,7 @@ public function testCalculateDependencies() {
       ->setMethods(array('getFilterFormat'))
       ->getMock();
 
-    $dependencies = $this->entity->calculateDependencies();
+    $dependencies = $this->entity->calculateDependencies()->getDependencies();
     $this->assertContains('test_module', $dependencies['module']);
   }
 
-- 
GitLab