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

Issue fork drupal-3481695

Command icon 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:

Comments

a.dmitriiev created an issue. See original summary.

a.dmitriiev’s picture

Issue summary: View changes

a.dmitriiev’s picture

Status: Active » Needs review
Issue tags: +Starshot blocker
StatusFileSize
new2.95 KB

Uploading patch so that it can be used in Search Track issue of Drupal CMS.

a.dmitriiev’s picture

As 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.

a.dmitriiev’s picture

Title: Add config action to copy entity displays » Entity displays cloning requires special config action

phenaproxima made their first commit to this issue’s fork.

phenaproxima’s picture

Category: Feature request » Bug report

I'd call this a bug; the clone action as it currently exists doesn't work for entity displays.

smustgrave’s picture

Version: 10.4.x-dev » 11.x-dev
Status: Needs review » Needs work

There's 2 MRs but not sure which one to remove. Can 1 be closed or hidden.

a.dmitriiev’s picture

phenaproxima’s picture

Issue summary: View changes
Status: Needs work » Needs review

We've settled on !9874. I'm updating the issue summary to reflect that.

phenaproxima’s picture

Issue summary: View changes
a.dmitriiev’s picture

StatusFileSize
new5 KB

Uploading the updated patch to work with Drupal CMS Search track.

a.dmitriiev’s picture

Updated approach works for entity displays now, also with wildcard

b_sharpe’s picture

Status: Needs review » Reviewed & tested by the community

Code looks good and works, added comment as I'm not sure if this needs a doc update specific for config actions and/or recipes?

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

I think we might be able to fix setting the ID in entity displays and then this will be a little less special case.

phenaproxima’s picture

Status: Needs work » Needs review

So, good news and bad news.

The good news: yes, your idea seems to work. It supports this use case, and is tested:

core.entity_view_display.node.page.full:
  cloneAs: node.page.search_index

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:

core.entity_view_display.node.*.default:
  createCopy: search_result

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).

phenaproxima’s picture

Issue summary: View changes
phenaproxima’s picture

thejimbirch’s picture

We will need to update the docs and I assume this should have a change record also.

phenaproxima’s picture

thejimbirch’s picture

Status: Needs review » Reviewed & tested by the community

Amazing! Marking as RTBC.

thejimbirch’s picture

  • alexpott committed 9b7d24a6 on 10.4.x
    Issue #3481695 by phenaproxima, a.dmitriiev, thejimbirch, b_sharpe,...

  • alexpott committed a1b47eaf on 11.x
    Issue #3481695 by phenaproxima, a.dmitriiev, thejimbirch, b_sharpe,...
alexpott’s picture

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

Committed and pushed a1b47eafdb9 to 11.x and 9b7d24a6fad to 10.4.x. Thanks!

phenaproxima’s picture

Status: Reviewed & tested by the community » Fixed

🚀

a.dmitriiev’s picture

`createCopy` config action works as expected for Search Track of Drupal CMS recipe.

Thank you all!

Status: Fixed » Closed (fixed)

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