Allow "Clone display" to current bundle view mode (overwrite)

Created on 19 January 2024, about 1 year ago

Problem/Motivation

Sometimes view displays are configured very similar. For example, in Drupal Commerce having "Cart" and "Summary".
Especially when dealing with many many fields, it's super time-consuming to configure all the fields (same) multiple times for each view mode.

"Clone displays" already provides the required functionality to clone certain displays, but it doesn't allow to

  • Clone to the same (current) bundle. (only other bundles are shown as checkbox)
  • Overwrite an existing view mode with the cloned values. (That's just a helpful UX thing. As workaround you could for now just delete the view mode to clone into. But of course you'd have to know that)

Steps to reproduce

Proposed resolution

  1. In "Clone displays" (.../fields/tools/clone-displays) allow selecting the current bundle as target
  2. Add a (required) select to select the target view mode. As default, the name of the current (source) view mode is selected. If selecting a different view mode, its values are overwritten with the current one

That way you could use the existing display as basis to overwrite an existing display that needs to be configured similarly.

Remaining tasks

User interface changes

API changes

Data model changes

Feature request
Status

Active

Version

1.0

Component

Code

Created by

🇩🇪Germany Anybody Porta Westfalica

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

Merge Requests

Comments & Activities

  • Issue created by @Anybody
  • 🇩🇪Germany Anybody Porta Westfalica

    Of course, the functionality / UX could also be helpful for the other field tools, like form displays etc.!

  • First commit to issue fork.
  • Status changed to Needs review 6 months ago
  • Status changed to Needs work 6 months ago
  • 🇫🇷France Grimreaper France 🇫🇷

    Hi,

    Thanks for the MR.

    I put a review comment. And here are my global feedbacks.

    The "overwrite" feature asked in the original issue and I also think this will be useful, is not implemented.
    I think the form needs to be simplified, having all those behaviors with #states is confusing and error prone.

    I have:
    - created the toto and tata view modes on content type.
    - enabled the tata entity view display on basic page
    - wanted to clone tata into toto for basic page
    - obtained the following fatal error

    The website encountered an unexpected error. Try again later.
    
    Drupal\Core\Entity\EntityStorageException: 'entity_view_display' entity with ID 'node.page.tata' already exists. in Drupal\Core\Entity\EntityStorageBase->doPreSave() (line 519 of core/lib/Drupal/Core/Entity/EntityStorageBase.php).
    Drupal\Core\Entity\EntityStorageBase->save(Object) (Line: 257)
    Drupal\Core\Config\Entity\ConfigEntityStorage->save(Object) (Line: 354)
    Drupal\Core\Entity\EntityBase->save() (Line: 613)
    Drupal\Core\Config\Entity\ConfigEntityBase->save() (Line: 166)
    Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay->save() (Line: 146)
    Drupal\field_tools\DisplayCloner->cloneDisplay(Object, 'page', 'toto') (Line: 225)
    Drupal\field_tools\Form\EntityDisplayBulkCloneForm->submitForm(Array, Object)
    call_user_func_array(Array, Array) (Line: 129)
    Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 67)
    Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 597)
    Drupal\Core\Form\FormBuilder->processForm('field_tools_displays_clone_form', Array, Object) (Line: 326)
    Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
    Drupal\Core\Controller\FormController->getContentResult(Object, Object)
    call_user_func_array(Array, Array) (Line: 123)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 638)
    Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 121)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 181)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
    Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 53)
    Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 28)
    Drupal\Core\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 32)
    Drupal\big_pipe\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 106)
    Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
    Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 36)
    Drupal\Core\StackMiddleware\AjaxPageState->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 741)
    Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
    require('/project/app/index.php') (Line: 4)
    

    So I guess in some loops tata is taken to be cloned too.

    Attaching screenshots of the steps to reproduce the error.

  • Assigned to niber
  • Status changed to Active 6 months ago
  • Status changed to Needs work 6 months ago
  • 🇫🇷France Grimreaper France 🇫🇷

    Hi,

    As there is already work done on the issue, the status should remain "Needs work", https://www.drupal.org/docs/develop/issues/fields-and-other-parts-of-an-... .

  • Issue was unassigned.
  • Status changed to Needs review 6 months ago
  • Status changed to Needs work 6 months ago
  • 🇫🇷France Grimreaper France 🇫🇷

    Nice!

    The form is way more simple to handle and nice to have added validation.

    The overwrite of an existing display is almost ok. As you can see on the video recording, the "links" configuration are not properly reset when overwritting, but ok when cloning for the first time.

  • Status changed to Needs review 5 months ago
  • Thanks for your code review !
    I just fixed the phpcs warning and errors on DisplayCloner and EntityDisplayBulkCloneForm php files.

  • Assigned to niber
  • Status changed to Needs work 5 months ago
  • Issue was unassigned.
  • Status changed to Needs review 5 months ago
  • Added a new separated form for cloning to a display for the current bundle. Made this for more readability/intuitive usage.

  • First commit to issue fork.
  • 🇫🇷France maboy

    Hello,

    All these cases have been tested and worked on my side with MR 11 :

    • Clone a view mode without layout builder in another bundle (destination view mode not existing)
    • Clone a view mode without layout builder in another bundle (destination view mode existing and layout builder mode is disabled)
    • Clone a view mode without layout builder in another bundle (destination view mode existing and layout builder mode is enabled)
    • Clone a view mode without layout builder in the same bundle (destination view mode existing and layout builder mode is disabled)
    • Clone a view mode without layout builder in the same bundle (destination view mode existing and layout builder mode is enabled)

    Regards,

  • 🇫🇷France Grimreaper France 🇫🇷

    Hello,

    I have rebased the MR and generate a patch file for Composer from latest version.

  • 🇫🇷France Grimreaper France 🇫🇷

    Here is a patch from the new MR which cumulates changes from this issue and Support Layout Builder Active .

  • 🇫🇷France Grimreaper France 🇫🇷

    I have tested some cases from comment 16 and comment #3255606-9: Support Layout Builder .

    Works perfectly.

    Thanks!

Production build 0.71.5 2024