diff --git a/core/includes/config.inc b/core/includes/config.inc index ef43774..79f9ce2 100644 --- a/core/includes/config.inc +++ b/core/includes/config.inc @@ -34,7 +34,7 @@ function config_install_default_config($type, $name) { if (empty($config_changes)) { return; } - $remaining_changes = config_import_invoke_owner($config_changes, $source_storage, $target_storage); + $remaining_changes = config_import_invoke_owner($config_changes, $source_storage, $target_storage, $name); config_sync_changes($remaining_changes, $source_storage, $target_storage); } } @@ -175,10 +175,14 @@ function config_import() { * The storage to synchronize configuration from. * @param Drupal\Core\Config\StorageInterface $target_storage * The storage to synchronize configuration to. + * @param string|false $module_name + * (optional) If this config is provided as a default by a module, that module + * will be stored as the owner for this config. Otherwise, the owner module + * will be stored. * * @todo Add support for other extension types; e.g., themes etc. */ -function config_import_invoke_owner(array $config_changes, StorageInterface $source_storage, StorageInterface $target_storage) { +function config_import_invoke_owner(array $config_changes, StorageInterface $source_storage, StorageInterface $target_storage, $module_name = FALSE) { // Allow modules to take over configuration change operations for // higher-level configuration data. // First pass deleted, then new, and lastly changed configuration, in order to @@ -197,6 +201,12 @@ function config_import_invoke_owner(array $config_changes, StorageInterface $sou $data = $source_storage->read($name); $new_config = new Config($name, $target_storage); if ($data !== FALSE) { + // Store the module responsible for this config. If it was provided as + // a default, use the providing module name. Otherwise, use the owning + // module name. + $data += array( + 'module' => $module_name ?: $module, + ); $new_config->setData($data); } diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php index 330f39c..e6a4f14 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php @@ -26,6 +26,13 @@ protected $originalID; /** + * The module providing this configuration entity. + * + * @var string + */ + public $module; + + /** * Overrides Entity::__construct(). */ public function __construct(array $values, $entity_type) { diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php b/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php index 2206dcf..553c034 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php @@ -112,7 +112,10 @@ public function load(array $ids = NULL) { $entities = $passed_ids; } - return $entities; + // Only return entities for enabled modules. + return array_filter($entities, function ($entity) { + return module_exists($entity->get('module')); + }); } /** diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigDefaultTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigDefaultTest.php new file mode 100644 index 0000000..c3d7bd4 --- /dev/null +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigDefaultTest.php @@ -0,0 +1,68 @@ + 'Default configuration', + 'description' => 'Tests configuration provided by other modules.', + 'group' => 'Configuration', + ); + } + + /** + * Tests loading configuration while the providing module is disabled. + */ + function testWhileDisabled() { + $dynamic_name = 'config_test.dynamic.dependent'; + $this->enableModules(array('config_test')); + + config_install_default_config('module', 'config_test'); + config_install_default_config('module', 'config_test_dependent'); + + // Verify the default configuration values exist. + $config = config($dynamic_name); + $this->assertIdentical($config->get('id'), 'dependent'); + + $entity = entity_load('config_test', 'dependent'); + $this->assertFalse(!empty($entity)); + } + + /** + * Tests loading configuration while the providing module is enabled. + */ + function testWhileEnabled() { + $dynamic_name = 'config_test.dynamic.dependent'; + $this->enableModules(array('config_test', 'config_test_dependent')); + + config_install_default_config('module', 'config_test'); + config_install_default_config('module', 'config_test_dependent'); + + // Verify the default configuration values exist. + $config = config($dynamic_name); + $this->assertIdentical($config->get('id'), 'dependent'); + + $entity = entity_load('config_test', 'dependent'); + $this->assertTrue(!empty($entity)); + } + +} diff --git a/core/modules/config/tests/config_test_dependent/config/config_test.dynamic.dependent.yml b/core/modules/config/tests/config_test_dependent/config/config_test.dynamic.dependent.yml new file mode 100644 index 0000000..cf16418 --- /dev/null +++ b/core/modules/config/tests/config_test_dependent/config/config_test.dynamic.dependent.yml @@ -0,0 +1,2 @@ +id: dependent +label: Dependent diff --git a/core/modules/config/tests/config_test_dependent/config_test_dependent.info b/core/modules/config/tests/config_test_dependent/config_test_dependent.info new file mode 100644 index 0000000..95d0588 --- /dev/null +++ b/core/modules/config/tests/config_test_dependent/config_test_dependent.info @@ -0,0 +1,5 @@ +name = Configuration test dependent module +package = Core +version = VERSION +core = 8.x +hidden = TRUE diff --git a/core/modules/views/lib/Drupal/views/Plugin/Core/Entity/View.php b/core/modules/views/lib/Drupal/views/Plugin/Core/Entity/View.php index 3f39af8..04a4f37 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/Core/Entity/View.php +++ b/core/modules/views/lib/Drupal/views/Plugin/Core/Entity/View.php @@ -133,13 +133,6 @@ class View extends ConfigEntityBase implements ViewStorageInterface { protected $executable; /** - * The module implementing this view. - * - * @var string - */ - protected $module = 'views'; - - /** * Overrides Drupal\Core\Entity\EntityInterface::get(). */ public function get($property_name, $langcode = NULL) { diff --git a/core/modules/views/lib/Drupal/views/ViewStorageController.php b/core/modules/views/lib/Drupal/views/ViewStorageController.php index 05268d2..fbdfac3 100644 --- a/core/modules/views/lib/Drupal/views/ViewStorageController.php +++ b/core/modules/views/lib/Drupal/views/ViewStorageController.php @@ -16,21 +16,6 @@ class ViewStorageController extends ConfigStorageController { /** - * Overrides Drupal\config\ConfigStorageController::load(); - */ - public function load(array $ids = NULL) { - $entities = parent::load($ids); - - // Only return views for enabled modules. - return array_filter($entities, function ($entity) { - if (module_exists($entity->get('module'))) { - return TRUE; - } - return FALSE; - }); - } - - /** * Overrides Drupal\config\ConfigStorageController::attachLoad(); */ protected function attachLoad(&$queried_entities, $revision_id = FALSE) {