Problem/Motivation
I think it would be useful for a recipe to say, for example, "make this change to all content types". Currently, I'm not aware of any way to do that.
Proposed resolution
In the config:actions section of recipe.yml, I'd suggest we support syntax like in #7:
config:
actions:
core.entity_view_display.node.*.*:
- setComponent:
field: field_foo
settings: {}
core.entity_form_display.node.*.*:
- setComponent:
field: field_foo
settings: {}
In this example, if you know you have instantiated field_foo on every content type (without necessarily knowing the exact names of those content types), you might want to be sure it is visible on the form and view displays of every content type.
We identified several potential use cases for a feature like this (the actual syntax we come up with might vary):
- Adding the same permission(s) to all user roles (#3420209: Allow config actions to be applied to multiple config entities using wildcards):
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 - Granting bundle-specific permissions to a particular role, for every bundle of a particular entity type (#3420516: Create config actions that can grant a set of bundle-specific permissions for all bundles of an entity type):
user.role.media_creator: grantPermissionsPerMediaType: - 'create %bundle media' - 'edit own %bundle media' - 'delete own %bundle media' - Instantiating a field on all bundles of the storage's target entity type (#3420521: Create a config action that can instantiate a field on every bundle of the target entity type):
field.storage.node.field_tags: instantiateOnAllBundles: label: Tags description: 'Add some tags here.' - Changing settings on every instance of a field (#3420209: Allow config actions to be applied to multiple config entities using wildcards):
field.field.media.*.field_tags: setSettings: auto_create: false - Adding every content type to a particular workflow (#3422821: Add a config action to add entity types and bundles to a Content Moderation workflow):
workflows.workflow.editorial: addAll: node_type - Creating a view display (i.e., enabling a view mode) for every content type (#3420209: Allow config actions to be applied to multiple config entities using wildcards):
core.entity_view_display.node.*.foo: ensure_exists: # The contents of the view display here...
Obviously, some of these need to be implemented differently than others. So these cases should be thought through further, and split out into their own issues.
In general, though, I see two patterns in these use cases:
- The ability to expand the meaning of
*. This could be accomplished in a pretty straightforward manner, I think;\Drupal\Core\Recipe\RecipeRunner::processConfiguration()could convert*into a regex, and apply it against all existing configuration names to find the one(s) that the action should apply to. This would add up to a few extra lines in that method. Let's do that in #3420209: Allow config actions to be applied to multiple config entities using wildcards. - New config actions that belong only to particular config entity types, allowing them to take advantage of the specific nature and superpowers of those entity types. Examples:
- A field storage can instantiate itself on every bundle of its target entity type. This would be a new config action that exists only on field storages. We have #3420521: Create a config action that can instantiate a field on every bundle of the target entity type for implementing this; it's not blocked on anything.
- Adding a particular entity type and bundle (or all bundles of a particular entity type!) to workflows that use Content Moderation. This applies only to Content Moderation. I'm not sure how exactly to approach this, since this actually requires targeting the plugin that backs the workflow config entity. The point is that this config action would be supported only by Content Moderation's workflows. I've opened #3422821: Add a config action to add entity types and bundles to a Content Moderation workflow to figure this out.
- Changing field (or field storage) settings. (This could be done using the feature being built in #3420209: Allow config actions to be applied to multiple config entities using wildcards.)
Because of their specificity, I think each of these cases (or any others we think of) would need to be done in their own issues.
Comments
Comment #2
phenaproximaComment #3
thejimbirch commentedI like it. Some use cases I can think of.
1. Add a field to multiple entity types using the
setComponentconfig action.2. Updating multiple filter.formats using the
setFilterConfigconfig action.3. Adding permissions to multiple user roles using the
grantPermissionsconfig action.Comment #4
thejimbirch commentedFor clarity, I think the recipe snippet in the description should be.
Comment #5
wim leers🤔 Is this expressive enough?
I think it is, but I'm wondering if there's use cases we're not thinking of yet. It's fine to gradually expand what we can do, with one important caveat: the syntax we choose here MUST NOT prevent future evolution.
Comment #6
wim leersAlso:
setQueueThumbnailDownloadsStatus()on media types is a pretty obscure use case. Can you expand the issue summary with some more real-world use cases? 🙏Comment #7
phenaproxima#6: You know...as I think about it, I can't find too many use cases where we'd need to, for example, do the same operation to every node type directly.
But I can easily imagine a situation where you'd want to, say, instantiate the same field on every content type. That's a completely different sort of operation, but I think we'll run into it a lot more often.
Probably the way I would expect that case to be represented in a
recipe.ymlis something like this:So, something like that would require two things:
instantiateAllaction for field storages, which allows a field to be created on all bundles of the target entity typeI'll update the issue summary to reference this - "add this field to the entity view displays of every content type" is a perfect case for why this feature would be necessary.
Comment #8
phenaproximaComment #9
phenaproximaIssue summary is now updated with a more realistic use case. :)
Comment #10
phenaproximaComment #11
wim leers#7++ that seems more common for sure!
… or match a certain pattern, such as
node.type.*orfield.field.*.*.*. Not sure which terminology is the best match to maximize recipe authoring usability.Comment #12
borisson_Would this allow us to remodel "Search api db defaults" as a recipe that can apply those (or at least some) defaults to all content types on a site?
A high level overview of what that module currently does is:
- Configures a search api server + index
- Adds and configures a view
- Adds a new view mode to basic page + article
- Adds all those bundles to search api
Comment #13
wim leersI think that'd be an excellent example :)
Did you mean ? 🤔
Comment #14
borisson_The current implementation is only on those, but it should do all node types.
See https://git.drupalcode.org/project/search_api/-/tree/8.x-1.x/modules/sea...
Comment #15
phenaproximaAnother variation on this use case - what if you want to grant a polymorphic permission (such as "edit own page content", "edit own article content", etc. -- the same permission, but repeated for each bundle of an entity type) to a role?
In other words, what if you have a "super editor" role, and you want to give that role the ability to edit every possible content type, without knowing ahead of time what the content types were, and without going so far as to grant "administer nodes" (or "bypass node access")? I don't think a recipe could that right now.
It would be cool to be able to do a config action like this:
That, I imagine, would be relatively straightforward -- a whole new config action for node types. You could also have a similar one for, say, media types (
grantAllMediaTypePermissions), since they're designed similarly to node types.Comment #16
wim leersLooks like we added so many needs/use cases that that warrants at least expanding this issue summary and potentially converting this to a meta/plan issue (and implementing each use case in a child issue, with cross-coordination in this issue)?
Comment #17
phenaproximaAdding some example use cases to the issue summary.
Comment #18
phenaproximaFixing an HTML error in the issue summary.
Comment #19
phenaproximaComment #20
phenaproximaComment #21
phenaproximaDistilled my thoughts on the patterns we're seeing emerge here.
Comment #22
phenaproximaComment #23
phenaproximaComment #24
phenaproximaSelf-assigning to update the issue summary.
Comment #25
phenaproximaComment #26
phenaproximaComment #27
phenaproximaComment #28
phenaproximaAdding #3422821: Add a config action to add entity types and bundles to a Content Moderation workflow to the issue summary.
Comment #29
thejimbirch commentedAll child and related issues have been completed. Thanks for all the work on this!
Comment #30
thejimbirch commented