Problem/Motivation
In the parent issue the general entity clone action was created, but unfortunately for entity display the clone process requires changing the mode property, see here https://git.drupalcode.org/project/drupal/-/blob/11.x/core/lib/Drupal/Co... . Method createCopy is called in https://git.drupalcode.org/project/drupal/-/blob/11.x/core/modules/field... when the new entity display is added.
I believe this config action that mimics the behavior from admin UI will be useful.
Proposed resolution
The cloneAs config action should behave consistently, and not need to special-case entity displays. They should be able to properly handle changes to their ID, so override their set() method to update the target entity type, bundle, and view mode when the ID changes. This unlocks stuff like:
# Clone a particular display into another content type, with the same view mode. This can't be used with wildcards because the clone's ID is static.
core.entity_view_display.node.page.3column:
cloneAs: node.blog.3column
Meanwhile, expose the createCopy() method as a normal config action, which allows wildcard compatibility:
# Create the search_result display as a copy of the full display, for all available content types.
core.entity_view_display.node.*.full:
createCopy: search_result
| Comment | File | Size | Author |
|---|---|---|---|
| #15 | 3481695-copy-entity-display-13.patch | 5 KB | a.dmitriiev |
Issue fork drupal-3481695
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3481695-entity-method
changes, plain diff MR !9874
- 3481695-add-config-action
changes, plain diff MR !9871
Comments
Comment #2
a.dmitriiev commentedComment #4
a.dmitriiev commentedUploading patch so that it can be used in Search Track issue of Drupal CMS.
Comment #5
a.dmitriiev commentedAs functionality mimics what field_ui module is doing, I placed the config action there, but maybe there is a better place for it. Also the tests are needed, I guess.
Comment #6
a.dmitriiev commentedComment #9
phenaproximaI'd call this a bug; the clone action as it currently exists doesn't work for entity displays.
Comment #10
smustgrave commentedThere's 2 MRs but not sure which one to remove. Can 1 be closed or hidden.
Comment #12
a.dmitriiev commentedClosing MR https://git.drupalcode.org/project/drupal/-/merge_requests/9871 in favor of https://git.drupalcode.org/project/drupal/-/merge_requests/9874 to have more general solution in place.
Comment #13
phenaproximaWe've settled on !9874. I'm updating the issue summary to reflect that.
Comment #14
phenaproximaComment #15
a.dmitriiev commentedUploading the updated patch to work with Drupal CMS Search track.
Comment #16
a.dmitriiev commentedUpdated approach works for entity displays now, also with wildcard
Comment #17
b_sharpe commentedCode looks good and works, added comment as I'm not sure if this needs a doc update specific for config actions and/or recipes?
Comment #18
alexpottI think we might be able to fix setting the ID in entity displays and then this will be a little less special case.
Comment #19
phenaproximaSo, good news and bad news.
The good news: yes, your idea seems to work. It supports this use case, and is tested:
The catch is that this pattern won't support wildcards, which is specifically needed by @a.dmitriiev to get Drupal CMS's search indexing to work. So I had to expose
createCopy()as an action method for that case:This necessitated a change to the EntityMethod action, which doesn't account for the possibility of the method returning a different entity (i.e., a clone).
Comment #20
phenaproximaComment #21
phenaproximaComment #22
thejimbirch commentedWe will need to update the docs and I assume this should have a change record also.
Comment #23
phenaproximaDone! https://www.drupal.org/node/3482871
Comment #24
thejimbirch commentedAmazing! Marking as RTBC.
Comment #25
thejimbirch commentedComment #28
alexpottCommitted and pushed a1b47eafdb9 to 11.x and 9b7d24a6fad to 10.4.x. Thanks!
Comment #29
phenaproxima🚀
Comment #30
a.dmitriiev commented`createCopy` config action works as expected for Search Track of Drupal CMS recipe.
Thank you all!