Problem/Motivation

In some cases, contrib and core modules provide functionality that is driven by config that for some use cases might be considered as content or - in general - you want to allow CRUD operations. For instances Yaml Forms / Webforms, Page Manager instances, Menus, etc.

Currently Config Readonly allows a boolean choice: can or cannot change any configuration.

Proposed resolution

Provide a hook_config_readonly_whitelist_patterns() where developers can define whitelisted configuration patterns for which CRUD operations are allowed even when Config Readonly is switched ON.

/**
 * Implements hook_config_readonly_whitelist_patterns().
 */
function MODULENAME_config_readonly_whitelist_patterns() {
  return [
    '*article2*',
    'system.performance',
  ];
}

Original Issue summary

First off, thanks for an excellent module; helps keep merge conflicts out of production, I'm sure it has saved us many headaches.

In some cases, modules and core provide functionality that is driven by config that for some use cases might be considered as content. For instance, at the company I work for, we like to provide our clients with a Form Builder so we give them the powerful YAML Form module. At the moment, we use a module that extends your module to add exceptions and use a combination of config import --partial and great care.

Since then I've been pointed to drush cexy and cimy (https://www.previousnext.com.au/blog/introducing-drush-cmi-tools) which allow certain config to be ignored when you make a decision for a site to effectively consider them instead as content.

If you are open to it, I would love to submit a patch that does two things:

- allow the administrator to add exceptions (potentially with wildcards)
- allow the administrator to additionally decide to have exceptions loaded from the ./drush/config-ignore.yml used by drush cexy/cimy

Would that be something you'd be willing to consider?

CommentFileSizeAuthor
#84 2826274-84.patch16.9 KBmanuel garcia
#84 interdiff-2826274-79-84.txt937 bytesmanuel garcia
#79 2826274-79.patch16.9 KBmanuel garcia
#79 interdiff-2826274-78-79.txt531 bytesmanuel garcia
#78 2826274-78.patch16.9 KBmanuel garcia
#78 interdiff-2826274-76-78.txt362 bytesmanuel garcia
#76 2826274-76.patch16.84 KBmanuel garcia
#76 interdiff-2826274-72-76.txt2.62 KBmanuel garcia
#74 interdiff-2826274-73-74.txt2.42 KBmanuel garcia
#73 2826274-72.patch16.68 KBmanuel garcia
#73 interdiff-2826274-70-72.txt691 bytesmanuel garcia
#70 2826274-70.patch16.68 KBmanuel garcia
#70 interdiff-2826274-67-70.txt1.05 KBmanuel garcia
#67 2826274-67.patch16.69 KBmanuel garcia
#67 interdiff-2826274-65-67.txt1.05 KBmanuel garcia
#65 2826274-65.patch16.56 KBmanuel garcia
#65 interdiff-2826274-61-65.txt2.36 KBmanuel garcia
#61 2826274-61.patch16.33 KBmanuel garcia
#61 interdiff-2826274-51-61.txt3.66 KBmanuel garcia
#59 interdiff-51-59.txt3.66 KBdouggreen
#59 2826274-59.patch16.76 KBdouggreen
#51 interdiff-2826274-45-51.txt689 bytesgaëlg
#51 2826274-51.patch15.4 KBgaëlg
#45 config_whitelist_to-2826274-45.patch15.39 KBscott_euser
#42 interdiff-2826274-37-42.txt980 bytesscott_euser
#42 config_whitelist_to-2826274-42.patch16.04 KBscott_euser
#37 interdiff-2826274-35-37.txt20.99 KBbircher
#37 interdiff-2826274-27-37.txt18.31 KBbircher
#37 2826274-37.patch15.86 KBbircher
#35 interdiff-2826274-27-35.txt9.1 KBscott_euser
#35 config_whitelist_to-2826274-35.patch14.3 KBscott_euser
#35 config_whitelist_to-2826274-35--with-fixed-module-test-issue-2851929.patch15.07 KBscott_euser
#27 interdiff-2826274-26-27.txt620 bytesscott_euser
#27 config_whitelist_to-2826274-27.patch11.19 KBscott_euser
#26 interdiff-2826274-24-26.txt5.83 KBscott_euser
#26 config_whitelist_to-2826274-26.patch11.46 KBscott_euser
#24 interdiff-2826274-20-24.txt3.25 KBscott_euser
#24 config_whitelist_to-2826274-24.patch11.19 KBscott_euser
#20 interdiff-2826274-16-20.txt31.32 KBscott_euser
#20 config_whitelist_to-2826274-20.patch11.14 KBscott_euser
#16 interdiff-2826274-16.txt16.09 KBscott_euser
#16 config_readonly_exceptions-2826274-16.patch28.83 KBscott_euser
#14 config_readonly_exceptions-2826274-14.patch28.6 KBscott_euser
#14 interdiff-2826274-14.txt1.91 KBscott_euser
#11 interdiff-2826274-11.txt757 bytesscott_euser
#11 config_readonly_exceptions-2826274-11.patch28.95 KBscott_euser
#8 interdiff-2826274-8.txt1.48 KBscott_euser
#8 config_readonly_exceptions-2826274-8.patch28.99 KBscott_euser
#5 config_readonly_exceptions-2826274-5.patch28.27 KBscott_euser
#5 exceptions-from-config-ignore-file.png94.54 KBscott_euser
#5 exceptions-manually-controlled.png88.98 KBscott_euser

Comments

scott_euser created an issue. See original summary.

micbar’s picture

Maybe this is related to your proposal.

I would like to unlock the /admin/structure/menu/manage/main form to allow users to drag menu items around and change the order.
I wonder if the weight of a menu link is content not config.

scott_euser’s picture

Yes, that is an example where for your site you'd like to make an exception. The proposed patch I would write would allow that.

micbar’s picture

I am interested in your patch! I had to disable this module.

scott_euser’s picture

This is a pretty hefty patch as it adds a lot of functionality, but I hope others also find it very useful.

You can:

  • Manually add config exceptions with or without wildcards
  • Automatically load config exceptions from your drush cexy/cimy config

It works for both drush/drupal console blocking as well as the admin / cms area blocking.

scott_euser’s picture

Assigned: scott_euser » Unassigned
Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 5: config_readonly_exceptions-2826274-5.patch, failed testing.

scott_euser’s picture

Re-run with config install and config setup (although a bit unsure about this!)

scott_euser’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 8: config_readonly_exceptions-2826274-8.patch, failed testing.

scott_euser’s picture

scott_euser’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 11: config_readonly_exceptions-2826274-11.patch, failed testing.

scott_euser’s picture

Status: Needs work » Needs review
StatusFileSize
new1.91 KB
new28.6 KB

Fix parse error

moshe weitzman’s picture

I think this makes sense from a feature point of view. I didnt code review, as patch looks a bit large.

scott_euser’s picture

Thanks for the comment and support for the feature moshe weitzman.

Yes it is a big patch, it offers a very significant amount of new functionality. To help a code reviewer, the files modified / added cover the following:

  1. Modifies the read-only form event subscriber to allow exceptions to pass through (in addition to what is already allowed to pass through)
  2. Modifies the check lock in the config read-only storage class to include what is being locked and check that against exceptions
  3. Creates a new config read-only exceptions service that loads the exceptions and compares a config against the exceptions (which is injected into the above two)
  4. Creates a new form to allow the user with the correct permissions to manage exceptions either via a repeating set of fields or by specifying a relative path to a config-ignore.yml file (compatible with drush cimy/cexy but not dependent upon)

As well, it provides the necessary tweaks / additions to the schema, tests, etc to handle the above.
I have made a couple naming modifications in the attached patch that will hopefully make it more clear + added a new permission so who can control the exceptions can be controlled.

pwolanin’s picture

Status: Needs review » Needs work

Calling it "Exceptions" is very confusing. It's a whitelist as asked for here: #2851286: Consider a whitelist to allow "some" configuration to be edited We need to rename all the things in the patch.

This patch is also too big and complex. I could possibly support a white list of config names in a simple config object. Having a service is confusing and overkill I think.

The whitelist config object should never be able to be modified in production.

pwolanin’s picture

Title: Config Read-only Exceptions » Config whitelist to allow "some" configuration to be edited while lock is active
scott_euser’s picture

Assigned: Unassigned » scott_euser

Thanks for the review, all makes sense. I will get batch to you with a much simplified patch offering the basics of the whitelist functionality.

scott_euser’s picture

StatusFileSize
new11.14 KB
new31.32 KB

I have greatly simplified this now:

  • Removed UI in favour of adding to settings.php like the existing read-only boolean
  • Changed service to a simple Trait class so it can be reused in the two existing classes without repeating the code and greatly simplified it
  • Simplified everything else and removed any coding standards complaints that happened in existing code

Where I got stuck with the test (it will fail):

  • I could not see how to get the test to test for instance node type page or article as I get a page not found at admin/structure/types/manage/article for instance even with adding node as a dependency of the test.

Bit of a restraint on the whitelist is it can't apply to ConfigFormBase because getEditableConfigNames is a protected function.

scott_euser’s picture

Assigned: scott_euser » Unassigned
gambry’s picture

  1. +++ b/src/Config/ConfigReadonlyStorage.php
    @@ -98,11 +100,17 @@ class ConfigReadonlyStorage extends CachedStorage {
    +   * CHeck whether config is currently locked.
    

    Comment starts with uppercase C and H.

  2. +++ b/src/ConfigReadonlyWhitelistTrait.php
    @@ -0,0 +1,127 @@
    +   * Get exceptions from config whitelist file.
    

    Are we happy to leave "exceptions" in here?

  3. +++ b/src/ConfigReadonlyWhitelistTrait.php
    @@ -0,0 +1,127 @@
    +   * Get single pattern from an exception.
    

    Same as above.

I could not see how to get the test to test for instance node type page or article as I get a page not found at admin/structure/types/manage/article for instance even with adding node as a dependency of the test.

Node module doesn't create any content type, the "standard" profile does. You'll need to use drupalCreateContentType(). I get some fatal errors adding this myself to the test, but probably it's just my instance.

gambry’s picture

After further tests:

  1. +++ b/src/Config/ConfigReadonlyStorage.php
    @@ -98,11 +100,17 @@ class ConfigReadonlyStorage extends CachedStorage {
    +    $this->checkLock($name);
    

    $name variable doesn't exist in this context.

  2. +++ b/src/Exception/ConfigReadonlyWhitelistException.php
    @@ -0,0 +1,8 @@
    +namespace Drupal\Core\Entity\Exception;
    

    Name space should be Drupal\config_readonly\Exception

  3. +++ b/src/ConfigReadonlyWhitelistTrait.php
    @@ -0,0 +1,127 @@
    +      throw new ConfigReadonlyWhitelistException($error);
    

    ConfigReadonlyWhitelistException class can't be found without the use statement.

scott_euser’s picture

Thanks for reviewing it @gambry, much appreciated!

Updated attached, getting there with the test, but the Trait is unable to read the file; I need to spend some more time to figure out how to write a file during a test as the file is readable from the test but not from the Trait. Will try to work on it further again later.

gambry’s picture

Apparently you can't use $this->writeSettings() twice in the same test, even with $this->resetAll(). Not sure if this is expect or a bug in core test framework.
Splitting in 2 tests works.

Besides I would personally separate the WhiteList tests in a separated class. In this way the 'node' dependency is not loaded when not needed (i.e for original config_readonly tests). But that is probably me being too picky.

ConfigReadonlyWhitelistTrait doesn't take in consideration the case when the setting "config_readonly_whitelist" is there but no file is provided ($whitelist is an empty string) and the case when the file is empty (returned $pattern is undefined).

This is an interesting and useful feature, really looking forward for using it!

scott_euser’s picture

Status: Needs work » Needs review
StatusFileSize
new11.46 KB
new5.83 KB

Nice one for solving that, was banging my head against the wall a bit wondering why it was failing; moved into a separate test file and worked fine!

I updated the trait to add that condition as well as set the default patterns empty array and added comments to make the method more clear.

scott_euser’s picture

StatusFileSize
new11.19 KB
new620 bytes

Cleaned up unused method from test.

The last submitted patch, 26: config_whitelist_to-2826274-26.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 27: config_whitelist_to-2826274-27.patch, failed testing.

gambry’s picture

Test fail due modules form being changed. I can't find exactly the commit, but I can see from the interface modules[Core][action][enable] should be now modules[action][enable]. That should probably be fixed before any other progress can be made here.

gambry’s picture

I've created #2851929: ReadOnlyConfigTest fails when using core 8.3.x or 8.4.x branches and submitted a patch. Until that is merged in we can temporary test against 8.2.x, as that should pass.

Patch at #27 looks good to me, if test is clean I'm assuming this can be RTBC.

pwolanin’s picture

I'm not sure I understand the motivation of using an external file as a whitelist source.

I think the whitelist itself should be a config object that cannot be changed while config is locked. Then you could track that together with other config changes?

scott_euser’s picture

Thanks @gambry for all the help and spotting that!

@pwolanin Essentially the idea is to keep it compatible with the drush cimy/cexy commands from PreviousNext which is being a more and more common workflow addressing a different part of the same problem this is trying to solve.

Easiest example case I can think:

  • You want to allow your client to use Webform (YAMLform) as their form builder on production and build their own forms. Webforms are stored in config, but in this use case, we want to consider them to be content.
  • You also want to lock config changes from happening on production.

How the combination of the two tools solves this:

  • drush cimy/cexy allows you to mark webform.* to be ignored in export and import so it never becomes part of your version control and doesn't get removed on import when not existing
  • config read-only with this patch then matches that exact behaviour by allowing webforms to be created and edited by the client

Some more info on drush cimy/cexy:

scott_euser’s picture

Assigned: Unassigned » scott_euser

Hold that thought, on considering this further, perhaps the two (config object & drush cimy/cexy compatibility) are not mutually exclusive and can be compatible with each other; I will revisit and see if it works; will try to get back to you in the next couple of days.

scott_euser’s picture

Assigned: scott_euser » Unassigned
Status: Needs work » Needs review
StatusFileSize
new15.07 KB
new14.3 KB
new9.1 KB

Updated to use config object via new form extending ConfigFormBase.

Confirmed that this is compatible with drush cimy/cexy so long as we use the key 'ignore' which deviates slightly from whitelist, but hopefully not a breaker (would like to avoid maintaining 2 whitelists, one for each tool).

Updated the test accordingly. The main patch will fail as per #31, so submitted a second discardable patch with that fix incorporated to show test pass.

Status: Needs review » Needs work

The last submitted patch, 35: config_whitelist_to-2826274-35.patch, failed testing.

bircher’s picture

StatusFileSize
new15.86 KB
new18.31 KB
new20.99 KB

Hello, please allow me to chime in.

Adding a text file is in my opinion not a good strategy.
configuring it via a configuration object can make sense, but to interact with it from another module one would have to start overriding configuration just for that.

What I had in mind was a service collector or a plugin, or at the very least a hook.
A hook seems to me to be the simplest form for now as you can always create a small module that implements that hook and reads from a text file, or from configuration.

Allow me to explain where this comes from: I maintain config_split, which is in my humble opinion a very elegant solution to prevent configuration of clients to be overwritten and to maintain development modules and config only in that environment. I am planning also to make it extensible so that other modules such as config_ignore could benefit from the same approach. It works with the basic drush commands as well (or it will as soon as I apply the patch in #2839452)
My plan is to make config_split and possibly config_ignore work with config_readonly.

bircher’s picture

Status: Needs work » Needs review

PS: I also incorporated 2851929-2 and I added the whitelist for simple configuration forms.

The last submitted patch, 24: config_whitelist_to-2826274-24.patch, failed testing.

The last submitted patch, 20: config_whitelist_to-2826274-20.patch, failed testing.

scott_euser’s picture

Thanks for working together on this @bircher, happy to see you involved! I am very keen to get this in in some form as these various modules could benefit from being combined with config read-only. I will try to test and review your patch before the end of the week.

For those interested in a comparison of where there is overlap (eg, drush cimy/cexy has a lot of overlap with config_split) @adamzimmerman has done a write up https://chromatichq.com/blog/managing-complex-configuration-drupal-8

scott_euser’s picture

StatusFileSize
new16.04 KB
new980 bytes

Looks solid to me; nice one solving the ConfigFormBase->getEditableConfigNames()!

I have attempted to make a simple module to bridge Drush CMI Tools and Config Read-only to test your patch and it was of course easy, so I am happy with this solution and I think it fits with #17 desire to keep it simple + is more flexible this way to work with other config related modules.

Just two minor tweaks:

  1. updated the description of the exception
  2. made the exception message more informative

For 2) added the config name in as a variable as per the exception docs as I found it difficult to debug without it. For instance, if you create a node type 'article' and you don't have a very liberal whitelist like '*article*' but instead something more specific like 'node.type.article' and 'article' the form does not get locked. Then when saving the form, the node module automatically attempts to adds a body field. Without the exception like this, it would be difficult to find out that that is why it was thrown.

jamesdeee’s picture

Assigned: Unassigned » jamesdeee
jamesdeee’s picture

Issue tags: +#SpringSprintLondon2017
scott_euser’s picture

StatusFileSize
new15.39 KB

Updated patch to match current version of dev brench. The code is the same, but where it sits relatively to the existing code has changed too much that interdiff doesn't seem to be able to handle it.

jamesdeee’s picture

What version of Drupal & Config Readonly are you doing this with, Scott? I'm still having a hard time getting the patch to apply.

scott_euser’s picture

This is what I'm doing to apply the patch:

cd modules/contrib && git clone --branch 8.x-1.x https://git.drupal.org/project/config_readonly.git
cd config_readonly
wget https://www.drupal.org/files/issues/config_whitelist_to-2826274-45.patch
git apply config_whitelist_to-2826274-45.patch
rm config_whitelist_to-2826274-45.patch

Let me know if that doesn't work for you.

gambry’s picture

Issue tags: -#SpringSprintLondon2017 +SpringSprintLondon2017
gaëlg’s picture

I wanted to allow users to reorder menu links (/admin/structure/menu/manage/main). I applied the patch and tried to whitelist 'system.menu.*' in the hook but it did not work.
After looking at the code, I figured out that the form is a config entity form, so I have to put the name of the entity in the whitelist: 'main'. But it seems to me like it's too wide and could lead to false positives because there is no "namespace". Some other config entity could also be named 'main', no?

gaëlg’s picture

Actually, replacing $name = $entity->getConfigTarget(); with $name = $entity->getConfigDependencyName(); in ReadOnlyFormSubscriber.php (at "// Don't block particular patterns.") solves the above problem. I can use system.menu.* in the whitelist.

But: I still have an error after reordering menu links when saving my view, because some menu links are config and not content (for example, a page view whose menu link is configured in the view configuration page). So I would have to whitelist all of these links, which implies allowing too much things (in the previous example, it would allow to edit the view although config readonly is activated).
I'm wondering if the problem of menu items reordering can be handled with this whitelist system. This might need another issue queue.

Edit: and here's the issue queue: #2892631: Don't block content menu links reordering

gaëlg’s picture

StatusFileSize
new15.4 KB
new689 bytes

Here's an updated patch to fix #49 by doing what I said in #50.

scott_euser’s picture

Thanks for the updated patch - confirmed this latest patch continues to work for my use cases.

daniel wentsch’s picture

Thanks for your efforts finding a solution to whitelisting certai configurations. What's not clear for me:
With the latest patch applied against dev – how would I define my whitelist?

scott_euser’s picture

You can do this to implement the whitelist with the latest patch:

/**
 * Implements hook_config_readonly_whitelist_patterns().
 */
function MODULENAME_config_readonly_whitelist_patterns() {
  return [
    '*article2*',
    'system.performance',
  ];
}
gambry’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

This is a really good solution. I think will need a future revisions, as per #37 and Config Filter, but this is more a overall Config Readonly roadmap and so to be discussed with maintainer(s) and generally out of the scope for this issue.

I've also updated the IS to reflect latest changes, as current version still mentions the yaml text file in the codebase for whitelisting.

vijaycs85’s picture

I have created Config Readonly Filter to solve this very same problem. As these configurations could be site/environment specific, having them as config entity and export with default configuration would be better. Probably we could add alter/hook to the discovery as well in future.

landsman’s picture

@vijaycs85 I think that this filter module should be in part of the main module.
What do you think? Is possible to merge it?

vijaycs85’s picture

@landsman sure, if we could add.

douggreen’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new16.76 KB
new3.66 KB

New patch attached:

  • I think we need an easy settings.php solution so I added config_readonly_readonly_whitelist_patterns to add patterns found in settings.
  • Any comment that says "this is a dirty hack. Look away" is going to get looked at closely. I've reworked that code to just document what it's doing.

I've tried to do minimal work on this patch. I did not address the following in my new patch:

  • I would prefer a service than a trait, given that $moduleHandler is defined in ConfigReadonlyWhitelistTrait but set in whatever uses the trait, and so that there's only one static cache of the whitelist (I am not sure, but a think use of the trait will have it's own local variables). I disagree that the service added a lot.
  • I'd like to see https://www.drupal.org/project/config_readonly_filter as a submodule or built into this patch more directly, so that the menu reorder use case is solved directly here.

@vijaycs85's solution is just another solution. I have not reviewed it. But as another contrib module solution, it shouldn't derail the work here.

Marking back to needs review for my most recent changes.

Status: Needs review » Needs work

The last submitted patch, 59: 2826274-59.patch, failed testing. View results

manuel garcia’s picture

Status: Needs work » Needs review
StatusFileSize
new3.66 KB
new16.33 KB

Rerolled #59 which would not apply, by applying #51 and then the interdiff #59 on top of it.

I had a look at the changes, my comments:
1. I think adding the settings.php option is a good addition as it opens up the possibility of defining these settings per environment.
2. The refactor of the "hack" is a great idea.

manuel garcia’s picture

Status: Needs review » Reviewed & tested by the community

I tested the following:

With this on my settings.php:

$settings['config_readonly'] = TRUE;
$settings['config_readonly_whitelist_patterns'] = [
  'system.menu.*',
  'core.menu.static_menu_link_overrides',
];

I was able to edit any menu on the system, tested:

  1. Changing the Title of the menu.
  2. Changing the Description of the menu.
  3. Adding new menu items to it.
  4. Deleting menu items from it.
  5. Enabling and disabling menu items.
  6. Re-ordering menu items.
  7. Editing menu items.
  8. Reseting menu items.

This all worked flawlessly, so switching back to RTBC.

pwolanin’s picture

Status: Reviewed & tested by the community » Needs review

in general, someone else should review if you wrote the last patch

pwolanin’s picture

Status: Needs review » Needs work

A few nits before this is done.

A bunch of @throws ConfigReadonlyStorageException should be fixed to use the full class name of the exception.

A place or two missing @throws, and some other doc comments.

  1. +++ b/src/Config/ConfigReadonlyStorage.php
    @@ -58,51 +65,59 @@ class ConfigReadonlyStorage extends CachedStorage {
    +   * @throws ConfigReadonlyStorageException
    

    Usually use fully namespaced name here

  2. +++ b/src/Config/ConfigReadonlyStorage.php
    @@ -58,51 +65,59 @@ class ConfigReadonlyStorage extends CachedStorage {
    +   *   Check for a specific lock name.
    

    This is a config name, not a lock name?

  3. +++ b/src/Config/ConfigReadonlyStorage.php
    @@ -58,51 +65,59 @@ class ConfigReadonlyStorage extends CachedStorage {
    +  protected function checkLock($name = '') {
    

    does this needs an @throws?

The new exception:
class ConfigReadonlyStorageException extends \Exception {}

should perhaps extend something a little more specific like \RuntimeException, and have a \n in the braces like core?

class AccessException extends \RuntimeException {
}
manuel garcia’s picture

Status: Needs work » Needs review
StatusFileSize
new2.36 KB
new16.56 KB

Addressing #64 - thanks @pwolanin for the review

douggreen’s picture

A few more minor comments. (Sorry I didn't notice these before. The first one is the only really important one.)

  1. +++ b/src/EventSubscriber/ReadOnlyFormSubscriber.php
    @@ -1,23 +1,31 @@
    +  /**
    

    Add a local variable for protected $moduleHandler.

  2. +++ b/src/EventSubscriber/ReadOnlyFormSubscriber.php
    @@ -41,20 +49,39 @@ class ReadOnlyFormSubscriber implements EventSubscriberInterface {
    +    if ($mark_form_read_only && $form_object instanceof EntityFormInterface) {
    

    I'd make this an elseif instead of an if. It is mutually exclusive from the previous conditional.

manuel garcia’s picture

StatusFileSize
new1.05 KB
new16.69 KB

Addressing #66.

douggreen’s picture

Status: Needs review » Reviewed & tested by the community

Thanks @manuel-garcia!

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 67: 2826274-67.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

manuel garcia’s picture

Status: Needs work » Needs review
StatusFileSize
new1.05 KB
new16.68 KB

Status: Needs review » Needs work

The last submitted patch, 70: 2826274-70.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

douggreen’s picture

@manuel-garcia, this is confusing that $moduleHandler is declared in the trait, but set in the class. Can we refactor so that it is defined and set in the same place? I suggest that we add a setter function to the trait, and call the trait setter function from the class constructor. That way the variable that the trait uses is self contained in the trait.

manuel garcia’s picture

Status: Needs work » Needs review
StatusFileSize
new691 bytes
new16.68 KB

The change to an elseif suggested in #66.2 is invalid. Reason being that the if the first if block runs, then $mark_form_read_only is assigned again.

manuel garcia’s picture

StatusFileSize
new2.42 KB

Re #72 I think that would be a strange pattern to implement. On the latest patch the module handler is not declared on the trait although it makes use of it on getWhitelistPatterns().
$moduleHandler is declared on the two classes that do use the trait (ReadOnlyFormSubscriber and ConfigReadonlyStorage).

I also tried a couple of other things:

  1. Pass the module handler to the trait methods. Still a strange thing to do, so no patch for this.
  2. Get rid of ConfigReadonlyWhitelistTrait::getWhitelistPatterns, and have the trait just hold matchesWhitelistPattern accepting a name and array of patterns. To me this seems like the cleaner trait, yet it means we having to get the patterns on several places instead of one.

So I am leaving the patch as is right now, perhaps the maintainers can weight in on this, I attach the interdiff of what implementing #72 would look like just in case.

pwolanin’s picture

Looks at examples in core some do seem to have setters or methods to interact with the variables defined by the trait.

see e.g. \Drupal\Core\Entity\DependencyTrait

in other cases they access the trait variable directly like

\Drupal\Core\Database\Query\InsertTrait

The variable in this patch is a service, which isn't something I've found used yet in core. I think I'd lean towards defining the property in the trait since it's used there. Or possibly requiring it to be passed into the trait;s method calls, but that seems like unneeded complexity.

A question, why is this method even public? seems to be used only internally to the service?

public function matchesWhitelistPattern($name)
manuel garcia’s picture

StatusFileSize
new2.62 KB
new16.84 KB

Thanks @pwolanin for weighting in on this, adding a setter for the module handler to the trait here.

Status: Needs review » Needs work

The last submitted patch, 76: 2826274-76.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

manuel garcia’s picture

Status: Needs work » Needs review
StatusFileSize
new362 bytes
new16.9 KB

Oops.

manuel garcia’s picture

StatusFileSize
new531 bytes
new16.9 KB

Re #75 I couldnt find a reason not to, so declaring matchesWhitelistPattern as protected here.

douggreen’s picture

Status: Needs review » Reviewed & tested by the community
douggreen’s picture

Status: Reviewed & tested by the community » Needs work

I just ran into an error when deploying one of our sites with this patch. I'm not sure yet the cause of the error, so I'm removing RTBC until I track it down. It might just be that we need to do a cache_clear before this runs, because of the new services, but let me track it down before anyone commits it.

douggreen’s picture

Status: Needs work » Reviewed & tested by the community

Marking this as RTBC now, we figured out that our builds need an additional 'drush cr' in our deploy scripts.

pwolanin’s picture

The use of the reflection class is a bit icky - is #2095289: Make getEditableConfigNames() public and use it in config_translation stalled? Looks like alexpott was willing to consider 8.x solutions.

Still a bit unsure why setModuleHandler() and getWhitelistPatterns() should be public (api additions)

manuel garcia’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new937 bytes
new16.9 KB
douggreen’s picture

@pwolanin Yes the reflection class is icky. We have no other possible solution in 8.x. Changing it is an API break. I tried to document this in the code as cleanly as possible by giving it it's own method, and by adding a @todo that says this can't be fixed in 8.x.

douggreen’s picture

Status: Needs review » Reviewed & tested by the community

Marking back to RTBC after testing @manuel-appnovation's changes. We still have the reflection. The best we can do is document this. I think it's documented sufficiently in the code, and that documentation has been reviewed here by a couple people. It's up to @pwolanin to accept or suggest how better to document it.

  • pwolanin committed f4cbb71 on 8.x-1.x
    Issue #2826274 by scott_euser, Manuel Garcia, bircher, douggreen, GaëlG...
pwolanin’s picture

Status: Reviewed & tested by the community » Fixed
scott_euser’s picture

Excellent, thank you!

Status: Fixed » Closed (fixed)

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

Prabhu.shan’s picture

Hi,

This is amazing module. Thanks everyone for the contribution. I would like to allow editing to admin --> people --> Permission and also for roles.Currently this modules locks down all the pages in configuration and also core modules - like installing modules.

elijah lynn’s picture

For those looking for documentation on this new feature it is here https://cgit.drupalcode.org/config_readonly/tree/README.txt