Problem/Motivation

Generally useful code for listing configuration types and for listing configuration entities of a given type are embedded in form generation code in ConfigSingleExportForm::buildForm and ConfigSingleImportForm::buildForm.

Signs that this code should be pulled into helper methods:

Proposed resolution

  • Add two new public methods to ConfigManagerInterface: listConfigTypes and listConfigByType.
  • Implement these two methods in ConfigManager.
  • Convert relevant code in ConfigSingleExportForm::buildForm and ConfigSingleImportForm::buildForm to use these methods.
  • Pull the string used to designate simple system configuration into a constant defined in ConfigManagerInterface. In doing so, change the string from 'system.simple' to 'system_simple' so that it is usable as a configuration key. This way, for example, the key can be used in a settings form for saving a given configuration type. Change all string references from 'system.simple' to ConfigManagerInterface::SYSTEM_SIMPLE_CONFIG.

Remaining tasks

User interface changes

API changes

Comments

nedjo’s picture

Status: Active » Needs review
StatusFileSize
new17.63 KB

Patch.

Status: Needs review » Needs work

The last submitted patch, 1: config-type-methods-2388833-1.patch, failed testing.

nedjo’s picture

StatusFileSize
new17.62 KB

Fix typo.

nedjo’s picture

Status: Needs work » Needs review
nedjo’s picture

Issue summary: View changes
jhodgdon’s picture

Status: Needs review » Needs work

I was asked to comment here because of my sandbox module Configuration Revert
https://www.drupal.org/sandbox/jhodgdon/2391835
However, I do not think that the methods here will be useful as they are for Configuration Revert. The first function getConfigTypes() is only returning the labels for the config types, and Config Revert needs to get the definitions because it needs more information, so this method isn't useful at all. The second function, getConfigByType I can't use either. So I'm not against adding these if another module can use them, but Config Revert can't really use them as they are.

It does look like the getConfigTypes idea is good because it is used even in Core twice. I'm not so sure about getConfigByType though. And I'm also not sure they belong on the class where they were put, because neither of the classes in Core that use these methods had that service injected previously. ??

Regarding the specifics of this patch, there are some small formatting, naming, and documentation issues:

a) This patch could be smaller if the new arguments to constructors and new member variables were added at the end of existing ones instead of at the middle. It makes it a bit hard to read the patch. Would you consider that change? For example, in the Export form:

   /**
-   * The config storage.
+   * The configuration manager.
    *
-   * @var \Drupal\Core\Config\StorageInterface
+   * @var \Drupal\Core\Config\ConfigManagerInterface
    */
-  protected $configStorage;
+  protected $configManager;
 
   /**
-   * Tracks the valid config entity type definitions.
+   * The config storage.
    *
-   * @var \Drupal\Core\Entity\EntityTypeInterface[]
+   * @var \Drupal\Core\Config\StorageInterface
    */
-  protected $definitions = array();
+  protected $configStorage;

If you had left configStorage wehre it was, and added the configManager to the end, the patch wouldn't have had all these bogus changes in it.

Then... in the interface:

  /**
+   * Get a list of all avaialble configuration types.
+   *
+   * @return array
+   *   An array of configuration type labels keyed by machine name.
+   *
+   */
+  public function getConfigTypes();

b) There's an extra line at the end here.

c) Name: "getConfigTypes" doesn't seem like the right name for a method that just returns the names of the config entity types plus "simple configuration".

d) The docs needs to say what the "machine name" is of "simple configuration", because that is not obvious.

e) "avaialble" is misspelled.

f) First line doc should start with "Returns" or "Lists", not "Get".

Now, also in the interface:

   /**
+   * Indicates simple system configuration. Defined with an underscore rather
+   * than a dot as it may be used as a configuration key.
+   */
+  const SYSTEM_SIMPLE_CONFIG = 'system_simple';

g) This needs a one-line summary. Put the second sentence into its own paragraph.

And also in the interface:

+  /**
+   * Get a list of all available configuration for a given type.
+   *
+   * @param string $config_type
+   *   The type of configuration to fetch.
+   *
+   * @return array
+   *   An array of configuration labels keyed by machine name.
+   */
+  public function getConfigByType($config_type);

h) First line should start with "Returns", "Lists", or "Gets", not "Get".

i) You need to document about what to pass in to list basic configuration that isn't an entity type.

j) I'm again not sure about the method name. "getConfig" says to me that it should return config, but really it's just listing the machine names and labels.

k)

+++ b/core/modules/config/src/Controller/ConfigController.php
@@ -78,6 +78,8 @@ public static function create(ContainerInterface $container) {
    *   The target storage.
    * @param \Drupal\Core\Config\StorageInterface $source_storage
    *   The source storage
+   * @param \Drupal\Core\Config\ConfigManagerInterface $config_manager
+   *   The configuration manager.
    * @param \Drupal\system\FileDownloadController $file_download_controller
    *   The file download controller.
    */

This adds a @param doc but nothing was added to the method???

nedjo’s picture

Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new17.14 KB

@jhodgdon: thanks for the detailed review and tips!

I've made changes to address the issues.

I'm also not sure they belong on the class where they were put, because neither of the classes in Core that use these methods had that service injected previously.

Yeah, I'm not sure either. They didn't seem to fit in any of the services already injected but I'm not sure if ConfigPackagerManager is right either. They might belong more in a set of config utilities, but there I didn't find such. Suggestions or pointers appreciated.

Besides fixes, the one change I've made is to add a boolean argument $include_simple_config to listConfigTypes(), on the assumption that there's a use case for fetching only config entity types.

Details of fixes:

a) moved service additions to end of existing list

b) removed extra line

c) renamed method to list rather than get

d) documented machine name of simple configuration.

e) fixed "avaialble".

f) fixed verb in first line of documentation

g) moved second line to its own paragraph

h) fixed verb beginning first line of documentation

i) added documentation on simple configuration machine name

j) renamed method to use list rather than get

k) removed unrelated documentation fix

Status: Needs review » Needs work

The last submitted patch, 7: config-type-methods-2388833-6.patch, failed testing.

nedjo’s picture

Status: Needs work » Needs review
StatusFileSize
new17.29 KB

Fix up ConfigManager::listConfigTypes().

dawehner’s picture

  1. +++ b/core/lib/Drupal/Core/Config/ConfigManager.php
    @@ -73,6 +73,13 @@ class ConfigManager implements ConfigManagerInterface {
    +  protected $definitions = array();
    

    what about name it entityTypes instead?

  2. +++ b/core/lib/Drupal/Core/Config/ConfigManager.php
    @@ -137,6 +144,67 @@ public function getConfigFactory() {
    +        if ($definition->isSubclassOf('Drupal\Core\Config\Entity\ConfigEntityInterface')) {
    

    Note: You could use ConfigEntityInterface::class instead

  3. +++ b/core/lib/Drupal/Core/Config/ConfigManager.php
    @@ -137,6 +144,67 @@ public function getConfigFactory() {
    +      $entity_types = array(
    +        ConfigManagerInterface::SYSTEM_SIMPLE_CONFIG => $this->t('Simple configuration'),
    +      ) + $entity_types;
    

    I'm wondering whether this constant really belongs into the config manager. It feels to belong more into \Drupal\Core\Config\ConfigBase instead, but yeah, not entirely sure.

  4. +++ b/core/lib/Drupal/Core/Config/ConfigManager.php
    @@ -137,6 +144,67 @@ public function getConfigFactory() {
    +      $config_prefixes = array_map(function (EntityTypeInterface $definition) {
    

    Should we typehint a bit stricter here and use ConfigEntityInterface instead?

  5. +++ b/core/lib/Drupal/Core/Config/ConfigManager.php
    @@ -137,6 +144,67 @@ public function getConfigFactory() {
    +      foreach ($names as $config_name) {
    +        foreach ($config_prefixes as $config_prefix) {
    +          if (strpos($config_name, $config_prefix) === 0) {
    +            unset($names[$config_name]);
    +          }
    +        }
    

    should we use array_filter here maybe? It would be a bit more explicit what is going on.

  6. +++ b/core/lib/Drupal/Core/Config/ConfigManagerInterface.php
    @@ -51,6 +59,32 @@ public function getEntityManager();
    +   * @param boolean $include_simple_config
    

    Note: We use 'bool' not 'boolean'

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

james.williams’s picture

StatusFileSize
new16 KB

Here's a re-rolled patch (still for 8.1.x, as that's what this issue is for... should it be made against 8.3.x now though?), including the dawehner's suggestions. For his point 3, I reckon the constant should remain in ConfigManagerInterface as that's the 'contract' for the code as an interface and, more relevantly, part of how the config should be managed as opposed to how the config 'exists'. But I can certainly see why it might want to go in ConfigBase instead - I can re-roll with it there if preferred.

Status: Needs review » Needs work

The last submitted patch, 12: config-type-methods-2388833-12.patch, failed testing.

james.williams’s picture

StatusFileSize
new16.01 KB

Just the wrong class suggested in point 4, I think :-) Changed to ConfigEntityTypeInterface, and in more than one place since the same change could be made in listConfigTypes() as well as listConfigByType().

james.williams’s picture

Status: Needs work » Needs review
jhodgdon’s picture

Version: 8.1.x-dev » 8.3.x-dev
james.williams’s picture

StatusFileSize
new15.96 KB

Here's a re-rolled patch against 8.3.x - I'm glad someone noticed :-)

jhodgdon’s picture

Status: Needs review » Needs work

I have a few small suggestions on the current patch -- which mostly looks good to me and I think satisfies all the goals of the issue summary:

  1. +++ b/core/lib/Drupal/Core/Config/ConfigManager.php
    @@ -69,6 +70,13 @@ class ConfigManager implements ConfigManagerInterface {
    +   * Tracks the valid config entity type definitions.
    

    I'm not sure about the word "Tracks" here. I think most of our variable doc blocks don't start with verbs.

  2. +++ b/core/lib/Drupal/Core/Config/ConfigManager.php
    @@ -69,6 +70,13 @@ class ConfigManager implements ConfigManagerInterface {
    +  protected $entityTypes = array();
    

    We use [] not array() in Drupal 8 code as a general rule.

  3. +++ b/core/lib/Drupal/Core/Config/ConfigManagerInterface.php
    @@ -46,6 +54,32 @@ public function getEntityManager();
    +  public function listConfigTypes($include_simple_config = TRUE);
    

    I am not sure if we can add functions to public interfaces at this stage of Drupal development. Any other classes that implement the interfaces would immediately be invalid (PHP errors if they don't implement the methods).

    So, we might need to put these two methods in a different interface, and make ConfigManager implement that one in addition (classes can implement multiple interfaces).

  4. +++ b/core/modules/config/src/Form/ConfigSingleExportForm.php
    @@ -157,41 +149,9 @@ public function updateExport($form, FormStateInterface $form_state) {
    +    return array(
    

    If we're fixing up this line of code, it should also be converted to use [] instead of array() syntax.

james.williams’s picture

StatusFileSize
new15.12 KB
new2.95 KB

Thanks - here's a patch+interdiff implementing those suggestions. I went with calling the new interface, 'ConfigListerInterface', which I hope is reasonable.

james.williams’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 19: config-type-methods-2388833-19.patch, failed testing.

james.williams’s picture

Status: Needs work » Needs review
StatusFileSize
new4.19 KB
new16.36 KB

Argh, missed the actual file for the new interface, sorry. Try again...

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

nedjo’s picture

Issue tags: +CMI 2.0 candidate

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

hardik_patel_12’s picture

StatusFileSize
new17.31 KB

Re-rolled against 9.1.x-dev

Status: Needs review » Needs work

The last submitted patch, 31: config-type-methods-2388833-31.patch, failed testing. View results

hardik_patel_12’s picture

StatusFileSize
new17.44 KB
new2.04 KB

Solving failure test cases.

hardik_patel_12’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 33: config-type-methods-2388833-33.patch, failed testing. View results

hardik_patel_12’s picture

Status: Needs work » Needs review
StatusFileSize
new17.45 KB
new253 bytes

Solving failure test cases.

jhodgdon’s picture

Status: Needs review » Needs work
Issue tags: +Needs issue summary update

Thanks for the updates!

This latest patch has some problems:

  1. A coder error, which you can see if you click through to the test results:
    core/modules/config/tests/src/Functional/ConfigSingleImportExportTest.php
    line 35	Doc comment is empty
    
  2. What is in the patch doesn't match the issue summary, so either the issue summary needs an update, or the patch needs an update -- the new methods are added to a new interface, not the interface suggested in the summary. I have not read the comments so I don't remember/know why this was done, so someone please update the issue summary or the patch so they are consistent.
  3. In ConfigSingleImportForm:
       /**
        * Constructs a new ConfigSingleImportForm.
    @@ -49,9 +47,10 @@ class ConfigSingleExportForm extends FormBase {
        * @param \Drupal\Core\Config\StorageInterface $config_storage
        *   The config storage.
        */
    -  public function __construct(EntityTypeManagerInterface $entity_type_manager, StorageInterface $config_storage) {
    +  public function __construct(EntityTypeManagerInterface $entity_type_manager, StorageInterface $config_storage, ConfigManagerInterface $config_manager) {
    
    ...
    +    $this->configManager = $config_manager;
    ...
    +      '#options' => $this->configManager->listConfigTypes(),
    ...
    +    ] + $this->configManager->listConfigByType($config_type);
    

    Two problems here:
    a) There was not a new @param added to the doc header in the constructor.
    b) The type hint for the new argument is ConfigManagerInterface, but the methods called later in the class, listConfigTypes() and listConfigByType(), are not on that interface but is instead on the new interface added to ConfigManager [see also previous item in this review]. So the type hint is not really correct.

  4. I suspect that core/modules/config/src/Form/ConfigSingleImportForm.php has the same problem as (b) from the previous comment too.
suresh prabhu parkala’s picture

Status: Needs work » Needs review
StatusFileSize
new16.44 KB

I have tried to add new methods in configManager as per issue summary and also tried to solve the issues mentioned in #37. The patch is here please review.

hardik_patel_12’s picture

@Suresh Prabhu Parkala, thank you for the patch but can you kindly provide interdiff also, so it will be helpful for other to keep tracking.

suresh prabhu parkala’s picture

StatusFileSize
new4.79 KB

Interdiff file for patch #36 and #38.

jhodgdon’s picture

Looking at the interdiff... I don't understand why this change was made in the ConfigManager class:

     // Store the list of dependents in three separate variables. This allows us
     // to determine how the dependency graph changes as entities are fixed by
     // calling the onDependencyRemoval() method.
+
     // The list of original dependents on $names. This list never changes.
     $original_dependents = $this->findConfigEntityDependentsAsEntities($type, $names, $dependency_manager);

We don't normally want blank lines after // comments, and even if we did, it doesn't seem to be related to this change?

But... actually I don't see that in the actual patch at all??? So I question whether the interdiff file is accurate?

So I went back to the actual patch in #38, which looks fine actually.

I do have one question though: By changing the key system.simple to system_simple for simple config, we are changing the URL that is used to export simple config, as you can see in this change in the test:

-    $this->drupalGet('admin/config/development/configuration/single/export/system.simple');
+    $this->drupalGet('admin/config/development/configuration/single/export/' . ConfigManagerInterface::SYSTEM_SIMPLE_CONFIG);

We need to see if this change is allowed for backwards compatibility. I kind of doubt that it is, and I'm not sure why we changed this value in the patch... there doesn't seem to be any discussion about it in this issue that I can see -- it is just in the issue summary and even though I possibly wrote the line in the issue summary about it, I'm not sure what exactly the implications are....

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new144 bytes

The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.