Reusing a field also copies display settings for non-existing displays and displays not enabled on the source

Created on 20 December 2023, about 1 year ago
Updated 29 January 2024, 11 months ago

Problem/Motivation

Reusing a field also copies display settings for non-existing displays and displays not enabled on the source.

Steps to reproduce

* Given node types Article and Page in standard.
* Have a field X on node type Article. Have an extra view display enabled where that field is configured for a view mode on Article, and one where it had been configured but has afterwards been disabled.
* Add that field on Page node type. This will auto-create new view displays, even in cases when the display on Article was disabled

Expected behavior: Only configuration for existing (on target) and enabled (on source or also on target? the latter could be OK) view displays should be copied.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component
Field 

Last updated 1 day ago

Created by

🇨🇭Switzerland berdir Switzerland

Live updates comments and jobs are added and updated live.
  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @berdir
  • Merge request !5900Resolve #3410012 "Reusing a field" → (Open) created by berdir
  • Status changed to Needs review about 1 year ago
  • 🇨🇭Switzerland berdir Switzerland

    Pushed fixes and some test to the MR.

    I think there was a misunderstanding in how getForm/ViewDisplay work, as they auto-create non-existing displays. It checked the status there, but they are enabled by default.

    I did keep the status check and switched to load with a check that the entity exists before the status call. I can see that updating a disabled *target* view display could be useful if you ever enable it again, it won't hurt now and you can review it when you do so and I guess that status() really should have been an isNew(). But didn't make that change yet.

    Test coverage could be extended to cover that case explicitly as well.

  • 🇨🇭Switzerland berdir Switzerland

    Fixed coding standards I think. FWIW, I think phpcs is wrong there, it's an array in a chained method call and now the save() calls are on the wrong line. But whatever :)

  • 🇮🇳India arisen Goa

    @Berdir the Steps to Reproduce are bit confusing.
    In the 2nd step does it mean disabled again instead of displayed again?

    Going by the functional test cases. The MR does seem to fix the reported issue.
    The disabled displays are not copied to the target entity on field reuse after applying the changes from the MR.

    Steps used for testing

    • Created a custom view mode, enabled it for Article node type.
    • Created a one more view mode. enabled it for Article node type.
    • Added a new field on Article content type, configured it to display on both the new display modes.
    • Disabled the 2nd display mode from Article node type.
    • In Page node type reused the newly added Article field. Observed the manage display for Page node type.
    • Before applying the MR changes, it did copy the disabled view display on Page node type.
    • It only created the enabled view display after applying MR.

    Looks like it will require more test coverage. Looking into the same.

  • 🇨🇭Switzerland berdir Switzerland
  • 🇨🇭Switzerland berdir Switzerland

    Yes, that should say disabled, clarified a bit.

    What test coverage do you think is missing?

  • First commit to issue fork.
  • 🇫🇮Finland lauriii Finland

    I'm wondering if we should special case the default modes and allow creating that in case that it doesn't exist? It looks like it's not guaranteed that all entity types create the default view mode for all bundles. Node module is ensuring that the default modes are created in node_add_body_field.

  • 🇨🇭Switzerland berdir Switzerland

    > I'm wondering if we should special case the default modes and allow creating that in case that it doesn't exist? It looks like it's not guaranteed that all entity types create the default view mode for all bundles.

    Maybe, if you create a new bundle and the very first field you add is a reused one then I guess it could not exist yet, I kept the logic that happens when we get no existing display configuration. That also would also fix that test fail I guess.

    Without that, I did switch to using load on purpose because creating config entities when we're not going to use them is inefficient, but I guess if we special case default then that makes sense.

  • First commit to issue fork.
  • Status changed to Needs work about 1 year ago
  • 🇺🇸United States smustgrave

    So even though I requested push access I couldn't rerun the failing javascript test. So I rebased to get them to run again.

    Ran the test-only feature and do see tests correctly failing.

    Can the issue summary be updated though, specifically the proposed solution

Production build 0.71.5 2024