Allow config actions to be applied to multiple config entities using wildcards

Created on 8 February 2024, 4 months ago
Updated 13 March 2024, 3 months ago

Problem/Motivation

This issue is spun off from #3418179: [meta] Make config actions more dynamic .

In that issue, we identified several use cases that follow a similar pattern. Such as...

Adding the same permission(s) to all user roles:

user.role.*:
  grantPermissions:
    - 'access content'

Affecting the view display of every content type in the same way -- say, by removing a component you don't want people to see:

core.entity_view_display.node.*.*:
  removeComponent: links

Changing settings on every instance of a field:

field.field.media.*.field_tags:
  setSettings:
    auto_create: false

Creating a view display (i.e., enabling a view mode) for every content type:

core.entity_view_display.node.*.foo:
  ensure_exists:
    # The contents of the view display here...

Overriding a base field for every media type:

core.base_field_override.media.*.thumbnail:
  ensure_exists:
    # The contents of the base field override here...

All of these uses have a similar need -- they have to be able to "select" the config items to change using * as a placeholder. Let's add that ability.

Proposed resolution

Right now, \Drupal\Core\Recipe\RecipeRunner::processConfiguration() very straightforwardly loops through every piece of config identified in a recipe's config:actions section.

Instead of taking each config name as given, we should run it through a transformation that first converts * to a regex (probably [a-z0-9_]+), then calls preg_grep() on the list of all config that exists in the active storage. Whatever comes out of that preg_grep() call is the actual list of config items that should have the action(s) applied.

User interface changes

None.

API changes

Yes, slightly new syntax for some use cases of recipes.

Feature request
Status

Fixed

Version

10.2

Component

Code

Created by

🇺🇸United States phenaproxima Massachusetts

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @phenaproxima
  • First commit to issue fork.
  • 🇺🇸United States phenaproxima Massachusetts
  • Merge request !72Wildcard config action → (Merged) created by narendraR
  • Pipeline finished with Failed
    4 months ago
    Total: 125s
    #93232
  • Pipeline finished with Failed
    4 months ago
    Total: 125s
    #94037
  • Pipeline finished with Success
    4 months ago
    Total: 1755s
    #94067
  • Pipeline finished with Success
    4 months ago
    Total: 140s
    #94673
  • Status changed to Needs review 4 months ago
  • 🇮🇳India narendraR Jaipur, India
  • 🇺🇸United States phenaproxima Massachusetts

    Oh, I love the way this is looking!

    I think w can harden it somewhat, and add more test coverage to be sure this really works as designed. :) Commented with some ideas.

  • Status changed to Needs work 4 months ago
  • 🇺🇸United States phenaproxima Massachusetts
  • Pipeline finished with Failed
    4 months ago
    Total: 121s
    #95615
  • Pipeline finished with Failed
    4 months ago
    Total: 231s
    #95638
  • 🇧🇪Belgium Wim Leers Ghent 🇧🇪🇪🇺

    Did a detailed review and provided some pointers.

    This relates to #3400672: [PP-1] Robustly validate the structure of recipe.yml , because this introduces a new way that would allow you to write invalid recipes.

  • Pipeline finished with Failed
    4 months ago
    Total: 146s
    #96479
  • Status changed to Needs review 4 months ago
  • 🇮🇳India narendraR Jaipur, India

    This MR still has phpstan issues, but wanted to make sure if this is heading in right direction.

  • Pipeline finished with Failed
    4 months ago
    Total: 266s
    #96530
  • Status changed to Needs work 4 months ago
  • 🇧🇪Belgium Wim Leers Ghent 🇧🇪🇪🇺

    Reviewed 🏓 Definitely heading in the right direction!

  • Pipeline finished with Canceled
    4 months ago
    Total: 75s
    #96917
  • Pipeline finished with Success
    4 months ago
    Total: 145s
    #96920
  • Pipeline finished with Failed
    4 months ago
    Total: 146s
    #97021
  • Pipeline finished with Canceled
    4 months ago
    Total: 45s
    #97025
  • Pipeline finished with Success
    4 months ago
    Total: 145s
    #97026
  • Pipeline finished with Success
    4 months ago
    Total: 236s
    #97042
  • 🇧🇪Belgium Wim Leers Ghent 🇧🇪🇪🇺

    Still needs more work — both @phenaproxima and I left remarks on what is missing/blocking RTBC.

  • Pipeline finished with Failed
    4 months ago
    Total: 148s
    #99204
  • Pipeline finished with Failed
    4 months ago
    Total: 236s
    #99726
  • Pipeline finished with Success
    4 months ago
    Total: 147s
    #99731
  • Pipeline finished with Success
    4 months ago
    Total: 262s
    #99755
  • Pipeline finished with Failed
    4 months ago
    Total: 139s
    #99797
  • Pipeline finished with Canceled
    4 months ago
    Total: 91s
    #99800
  • Pipeline finished with Failed
    4 months ago
    Total: 150s
    #99801
  • Pipeline finished with Failed
    4 months ago
    Total: 238s
    #99812
  • Pipeline finished with Failed
    4 months ago
    Total: 141s
    #99817
  • Pipeline finished with Failed
    4 months ago
    Total: 239s
    #100011
  • Pipeline finished with Failed
    4 months ago
    Total: 179s
    #100013
  • Status changed to Needs review 4 months ago
  • 🇺🇸United States phenaproxima Massachusetts

    Honestly, I'm not sure what else is needed here.

  • Pipeline finished with Success
    4 months ago
    Total: 171s
    #100015
  • Status changed to Needs work 4 months ago
  • 🇧🇪Belgium Wim Leers Ghent 🇧🇪🇪🇺

    Very close! 👏 I see at least one missing test, one unnecessary method and one accidental public API addition, so for that.

  • Pipeline finished with Canceled
    4 months ago
    Total: 17s
    #101687
  • Pipeline finished with Canceled
    4 months ago
    Total: 14s
    #101689
  • Pipeline finished with Canceled
    4 months ago
    Total: 26s
    #101691
  • Pipeline finished with Success
    4 months ago
    #101694
  • Pipeline finished with Failed
    4 months ago
    Total: 156s
    #101699
  • Pipeline finished with Failed
    4 months ago
    Total: 158s
    #101713
  • Pipeline finished with Failed
    4 months ago
    Total: 149s
    #101717
  • Status changed to Needs review 4 months ago
  • 🇺🇸United States phenaproxima Massachusetts

    I think it's ready for another look. All feedback resolved, except for one, which I'm not sure how to approach.

  • Pipeline finished with Success
    4 months ago
    Total: 161s
    #101718
  • Pipeline finished with Success
    4 months ago
    Total: 157s
    #101793
  • Pipeline finished with Success
    4 months ago
    Total: 159s
    #101795
  • Status changed to Needs work 4 months ago
  • 🇧🇪Belgium Wim Leers Ghent 🇧🇪🇪🇺

    Close, but NW for \Drupal\Core\Config\ConfigBase::validateName() and a test with a sample expression I provided that causes a PHP warning 🤓

  • Pipeline finished with Success
    4 months ago
    Total: 158s
    #102631
  • Pipeline finished with Success
    4 months ago
    Total: 157s
    #102635
  • Pipeline finished with Success
    4 months ago
    Total: 158s
    #102639
  • Status changed to Needs review 4 months ago
  • 🇺🇸United States phenaproxima Massachusetts
  • Status changed to RTBC 4 months ago
  • 🇧🇪Belgium Wim Leers Ghent 🇧🇪🇪🇺

    Agreed we can question the wisdom of `ConfigBase::validateName()`, but that's not up to Recipes to change. Recipes should be able to install any config that is valid. So let's open a core issue to tighten that instead? :blush:

    @chx requested in #1701014-63: Validate config object names to disallow | and a range of other characters (but not ( or )) and @xjm implemented it in #1701014-73: Validate config object names … but forgot |. So AFAICT the best course of action is to create a follow-up to tighten this in Drupal core 👍

  • 🇺🇸United States phenaproxima Massachusetts
  • First commit to issue fork.
  • Pipeline finished with Skipped
    4 months ago
    #105435
  • Status changed to Fixed 4 months ago
  • 🇬🇧United Kingdom alexpott 🇪🇺🌍

    Can someone file an issue against the documentation branch 1.x and add some docs from the issue summary about this. Thanks!

    • 49287cc9 committed on patch
      Update recipe 11.x patch 0954af94 Issue #3420209 by phenaproxima,...
    • 536bec39 committed on patch
      Update recipe 10.2.x patch bc2542b5 Issue #3420209 by phenaproxima,...
  • Status changed to Downport 4 months ago
  • 🇧🇪Belgium Wim Leers Ghent 🇧🇪🇪🇺

    @phenaproxima, can you act on #21 + #17? 🙏

  • 🇮🇳India narendraR Jaipur, India

    Created https://www.drupal.org/project/drupal/issues/3424296 🐛 Disallow |, ( and ) in config object names Active and https://www.drupal.org/project/distributions_recipes/issues/3424293

  • Status changed to Fixed 4 months ago
  • 🇬🇧United Kingdom alexpott 🇪🇺🌍
  • 🇧🇪Belgium Wim Leers Ghent 🇧🇪🇪🇺
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.69.0 2024