Problem/Motivation

The configuration system has a couple of areas that could do with tidying up. These have to be done together as the procedural code unnecessarily ties everything together.

  • Several of the procedural functions in config.inc have no OO equivalents impeding the ability to swap out functionality and unit test.
  • config.inc is included in _drupal_bootstrap_configuration() yet none of the functions it contains are regularly used during runtime.
  • The ConfigImporter is currently injecting services it is not using and additionally is calling out to procedural code.

Proposed resolution

  • Create a new ConfigManager that implements the functionality of contained with config.inc where appropriate
  • Remove or deprecate functionality in config.inc where appropriate
  • Remove unneeded dependencies from ConfigInstaller

This blocks beta since it is an API change to the configuration system. A followup should remove the include and usages of config(), typed_config() and config_get_storage_names_with_prefix().

Remaining tasks

Patch

User interface changes

None

API changes

  • Remove config_get_entity_type_by_name()
  • Remove config_uninstall_default_config()
  • Deprecate config_get_storage_names_with_prefix()
  • Deprecate typed_config()
  • Remove config_import_create_snapshot()
  • Remove config_diff()
  • Add ConfigManager
  • Change ConfigImporter constructor
  • Change ConfigInstaller constructor

Change records

There appears to be no change records to update as a result of this change. When we remove config() we should update https://drupal.org/node/2065313

Files: 
CommentFileSizeAuthor
#26 2188595-follow-up.patch1.59 KBandypost
PASSED: [[SimpleTest]]: [MySQL] 64,260 pass(es). View
#24 2188595-follow-up.patch1.59 KBandypost
PASSED: [[SimpleTest]]: [MySQL] 64,319 pass(es). View
#20 2188595.20.patch38.7 KBalexpott
PASSED: [[SimpleTest]]: [MySQL] 64,293 pass(es). View

Comments

alexpott’s picture

Status: Active » Needs review
FileSize
17.48 KB
PASSED: [[SimpleTest]]: [MySQL] 63,670 pass(es). View

Here's a patch doing what is outlined in the issue summary.

tim.plunkett’s picture

+++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityManager.php
@@ -0,0 +1,55 @@
+      return ($config_prefix = $entity_info->getConfigPrefix()) && strpos($name, $config_prefix . '.') === 0;

I know we use this check in other places, but why not switch to return $entity_info->isSubClassOf('\Drupal\Core\Config\ConfigEntityInterface');?

alexpott’s picture

+++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityManager.php
@@ -0,0 +1,55 @@
+    $entities = array_filter($this->entityManager->getDefinitions(), function (EntityTypeInterface $entity_info) use ($name) {
+      return ($config_prefix = $entity_info->getConfigPrefix()) && strpos($name, $config_prefix . '.') === 0;
+    });

Because we need the config entity prefix so that we can determine what type of config entity the supplied configuration name is.

tim.plunkett’s picture

Duh. I misread the snippet. Carry on.

alexpott’s picture

FileSize
817 bytes
18.35 KB
PASSED: [[SimpleTest]]: [MySQL] 63,732 pass(es). View

Now actually removing the function from config.inc

tim.plunkett’s picture

My only worry is that we're provide a wrapper around entity manager, but only one method (getStorageController). It provides a nice place for getEntityTypeIdByName, but it seems like there might be later confusion about whether one should use this or the entity manager directly for getting the storage controller.

  1. +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityManager.php
    @@ -0,0 +1,55 @@
    +  function getEntityTypeIdByName($name) {
    
    +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityManagerInterface.php
    @@ -0,0 +1,37 @@
    +  function getEntityTypeIdByName($name);
    

    public function

  2. +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityManager.php
    @@ -0,0 +1,55 @@
    +   * Returns the entity type of a configuration object.
    +   *
    +   * @param string $name
    +   *   The configuration object name.
    +   *
    +   * @return string|null
    +   *   Either the entity type name, or NULL if none match.
    

    This can be {@inheritdoc} since its on the interface

  3. +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityManager.php
    @@ -0,0 +1,55 @@
    + * Definition of Drupal\Core\Config\Entity\ConfigEntityManager.
    

    Contains \Drupal

  4. +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityManager.php
    @@ -0,0 +1,55 @@
    +use Drupal\Core\Entity\EntityTypeInterface;
    +
    +
    +/**
    

    Double blank line

  5. +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityManager.php
    @@ -0,0 +1,55 @@
    +  /**
    +   * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
    +   */
    +  public function __construct(EntityManagerInterface $entity_manager) {
    

    Constructs ... and missing the @param description

  6. +++ b/core/lib/Drupal/Core/Config/ConfigImporter.php
    @@ -110,24 +94,18 @@ class ConfigImporter {
    -    $this->configFactory = $config_factory;
    ...
    -    $this->uuidService = $uuid_service;
    

    Were these just completely unused? Heh.

jibran’s picture

FileSize
1.64 KB
18.23 KB
PASSED: [[SimpleTest]]: [MySQL] 63,689 pass(es). View

Fixed #6

alexpott’s picture

Title: Create a ConfigEntityManager to tidy up the ConfigImporter constructor » Create a ConfigManager to be able to remove config.inc
Issue summary: View changes
FileSize
38 KB
PASSED: [[SimpleTest]]: [MySQL] 64,220 pass(es). View

I agree with @timplunkett that we should avoid creating a confusion with the entity manager. I've refocussed the patch to address the ultimate aim which is removal of config.inc. The patch gets round the confusion by implementing getEntityManager() on the new ConfigManager() object so the ConfigImporter and ConfigInstaller don't need to have the EntityManager injected as well.

I have not provided an interdiff because the changes are extensive and main addition has been renamed resulting in an interdiff larger than the patch.

alexpott’s picture

Issue summary: View changes

Status: Needs review » Needs work

The last submitted patch, 8: 2188595.8.patch, failed testing.

xjm’s picture

Issue tags: +Kill includes

So, this is a good cleanup, but after having read the issue and the patch, I don't understand why it's critical or a beta blocker. I'd propose it as a major beta target/maybe beta deadline instead. We could even provide a deprecation/BC layer after beta, I think; it would just be cleaner not to.

Edit: In the summary, this statement has a false premise:

This blocks beta since it is an API change to the configuration system.

Not all API changes to CMI block beta -- only the critical ones. Non-critical ones (which IMO this is) should be done so the CMI API is stable and pleasant, but we'd release a beta with or without it and tough luck.

xjm’s picture

Issue summary: View changes

Also, re: the change record, we should update it, not delete it, so that there's something for people who ported with config() to find.

alexpott’s picture

Priority: Critical » Major
Issue tags: -beta blocker +beta target

Ok sure let's make it a beta target then - but I'd like to get this in before doing more work on the Importer because had all the additional services and lack of ability to right unit tests against annoys me.

alexpott’s picture

Status: Needs work » Needs review

8: 2188595.8.patch queued for re-testing.

alexpott’s picture

FileSize
1.12 KB
38 KB
PASSED: [[SimpleTest]]: [MySQL] 64,223 pass(es). View

Rerolled due to #2165155: Change $entity_type to $entity_type_id and $entity_info to $entity_type/$entity_types. Attached diff of two patches as interdiff possible.

Berdir’s picture

+++ b/core/core.services.yml
@@ -70,6 +70,9 @@ services:
     factory_class: Drupal\Core\Config\FileStorageFactory
     factory_method: getActive
+  config.manager:
+    class: Drupal\Core\Config\ConfigManager
+    arguments: ['@entity.manager', '@config.factory', '@config.typed', '@string_translation']
   config.storage:

Agree with the naming, change I found ConfigEntityManager also confusing, given that we're about to introduce ConfigEntityType, where it really is a subclass of EntityType with config specific additions.

Looks great to me.

Applied the patch, and the only remaining functions in there are config_get_storage_names_with_prefix(), config() and config_type(). config.inc still says "This is the API for configuration storage." in the @file declaration, which is obviously bogus.

Wondering if we don't simply want to go ahead and move those three left-over functions to bootstrap.inc or maybe even drop config_typed(), it's used in exactly one location outside of tests. If not that, then maybe an explicit follow-up issue to remove config.inc and delete those functions? The not-deleting of config() for example resulted in new calls to it that were introduced as late as 22. january 14 :( Or move + follow-up?

alexpott’s picture

I deprecated everything in config.inc with the idea of making it a follow up, so here it is: #2192693: Remove config.inc. I don't think there is any point in cleaning up the documentation in config.inc here as that issue will remove the entire file. I didn't remove all usages of the 3 remaining functions to keep the patch size sensible.

Berdir’s picture

Status: Needs review » Reviewed & tested by the community

Works for me, let's do this.

catch’s picture

Status: Reviewed & tested by the community » Needs work

Patch looks great overall, had a few nitpicks:

  1. +++ b/core/includes/config.inc
    @@ -70,26 +37,12 @@ function config($name) {
    + * @deprecated as of Drupal 8.0. Use \Drupal::service('config.typed') instead.
    

    Is this really deprecated or are we going to nuke it later?

  2. +++ b/core/lib/Drupal/Core/Config/ConfigManager.php
    @@ -0,0 +1,136 @@
    +    require_once DRUPAL_ROOT . '/core/lib/Drupal/Component/Diff/DiffEngine.php';
    

    Could use a @todo on https://drupal.org/node/1848266

alexpott’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
1.97 KB
38.7 KB
PASSED: [[SimpleTest]]: [MySQL] 64,293 pass(es). View

Fixed up the comments.

catch’s picture

Title: Create a ConfigManager to be able to remove config.inc » Change notice: Create a ConfigManager to be able to remove config.inc
Status: Reviewed & tested by the community » Active
Issue tags: +Missing change record
andypost’s picture

+++ b/core/lib/Drupal/Core/Config/ConfigManager.php
@@ -0,0 +1,138 @@
+  public function diff(StorageInterface $source_storage, StorageInterface $target_storage, $name) {
+    // @todo Replace with code that can be autoloaded.
+    //   https://drupal.org/node/2188595
+    require_once DRUPAL_ROOT . '/core/lib/Drupal/Component/Diff/DiffEngine.php';

needs follow-up, point to the issue

Berdir’s picture

@andypost: It already does, that is the follow-up issue?

andypost’s picture

Status: Active » Needs review
FileSize
1.59 KB
PASSED: [[SimpleTest]]: [MySQL] 64,319 pass(es). View

@Berdir see #19
Patch also fixes doc-block

alexpott’s picture

Status: Needs review » Reviewed & tested by the community

lol - I hang my head in shame

andypost’s picture

FileSize
1.59 KB
PASSED: [[SimpleTest]]: [MySQL] 64,260 pass(es). View
+++ b/core/lib/Drupal/Core/Config/ConfigManager.php
@@ -50,6 +50,12 @@ class ConfigManager implements ConfigManagerInterface {
+   *   he string translation service.

missed 'T'

xjm’s picture

Can we please not reuse majors for minor docs cleanups?

catch’s picture

Status: Reviewed & tested by the community » Active

Yes please start another issue for that and attach the patch there. It's also hard to tell whether the change notice or the patch is CNR/RTBC.

alexpott’s picture

Title: Change notice: Create a ConfigManager to be able to remove config.inc » Create a ConfigManager to be able to remove config.inc
Status: Active » Fixed

Change record https://drupal.org/node/2193603 created

alexpott’s picture

jibran’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.