Many unwanted entity_form_display entities created when updating to 2.0.0-rc8

Created on 11 May 2023, almost 2 years ago
Updated 14 June 2024, 9 months ago

Problem/Motivation

When updating from 8.x-1.3 to 2.0.0-rc8, after the update hook runs and we run config export, we noticed that there were many seemingly unnecessary and unwanted entity_form_display entities that were created.

In our particular case, we have an inordinate number of content types (236). We also have 14 entity_form_mode entities defined for nodes. At the end of the update hook, we end up with 236 * 14 = 3304 new entity_form_display config entities, eg. core.entity_form_display.node.<bundle>.<form_display>.yml, which before running the update we did not have.

We don't want all the new entity_form_display config entities. Are they necessary for the new version of scheduler?

Steps to reproduce

  • Install out of the box Drupal 9.5
  • Install scheduler at version 8.x-1.3
  • Add a entity form mode for nodes (/admin/structure/display-modes/form/add/node), but don't enable it / customize it on any particuler bundle
  • Export config
  • Update to scheduler 2.0.0-rc8, run the update hooks
  • Export config

Expected result

No new entity form displays.

Actual result

New entity_form_display config entites are created for each bundle, for the form mode created above, reflected in the config export.

Proposed resolution

Form modes that aren't already being used for a particular bundle, should be ignored by the scheduler update hook.

Remaining tasks

  • Verify the new entity_form_displays being created are unintentional
  • If unintentional and serve no practical purpose, fix the update hooks

User interface changes

None

API changes

None

Data model changes

Extra entity_view_display's are not created.

πŸ› Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

πŸ‡¨πŸ‡¦Canada m4olivei Grimsby, ON

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

Comments & Activities

  • Issue created by @m4olivei
  • πŸ‡¨πŸ‡¦Canada m4olivei Grimsby, ON
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 8
    last update almost 2 years ago
    229 pass
  • @m4olivei opened merge request.
  • Issue was unassigned.
  • Status changed to Needs review almost 2 years ago
  • πŸ‡¨πŸ‡¦Canada m4olivei Grimsby, ON

    See merge request.

  • πŸ‡¨πŸ‡¦Canada m4olivei Grimsby, ON
  • First commit to issue fork.
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 8
    last update almost 2 years ago
    229 pass
  • πŸ‡¬πŸ‡§United Kingdom jonathan1055

    Hi m4olivei,
    Thank you for taking the time to explain your scenario and to provide such detailed info. The change you suggest looks fine, and if it solves your problem then that's perfect. I will try your steps to reproduce.

    On #3320341-19: Disable fields in form displays by default β†’ you said:

    Specifically, this code does not consider that the $form_display object here may be new, and therefore, may be able to be skipped. However, the line $form_display->removeComponent($field)->save(); will remove a component it doesn't have (b/c it's new) and then save it, which actually creates it for the first time. I don't think this is intentional. I think any $form_display that is new should be skipped.

    Can you explain a bit more in what scenario the form display object will have the isNew() attribute. i.e when does not stop becoming 'new'. Is it after the first save?

    Do you think we need to add a test for this change? I am tempted to say not, as it would be a lot of work for a situation we can prove by manual testing. But would be interested to hear your thoughts.

  • πŸ‡¬πŸ‡§United Kingdom jonathan1055

    I've sucessfully replicated the probelm, and with the suggested fix it is solved.

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 8
    last update almost 2 years ago
    229 pass
  • πŸ‡¨πŸ‡¦Canada m4olivei Grimsby, ON

    Can you explain a bit more in what scenario the form display object will have the isNew() attribute. i.e when does not stop becoming 'new'. Is it after the first save?

    Sure thing! So, lets take a look at a bigger piece of the code in question here:

    The code is looping through for all entity types, for all bundles, for all form displays for the entity type. The key is line 1370, which will load the form display object:

    $form_display = $display_repository->getFormDisplay($entityTypeId, $bundle_id, $display_mode);

    If you look at Drupal's source code for this method, it will attempt to load the configuration object from active config, and if it's not found (doesn't exist), it will
    create a fresh config entity object. So either way you get this in memory form display object. In the update hook, when save() is
    called, for form displays that already existed for the entity typ e/ bundle combo, the expected behavior occurs. For entity type / bundle combos that didn't previously exist in active config, when save() is called, its persisted to active config for the first time. That results in the unintended extra form modes after the update hook runs.

    Does that make sense?

  • πŸ‡¬πŸ‡§United Kingdom jonathan1055

    Yes that makes perfect sense, and helps a lot. Thanks for taking the time to explain it. I knew it would be worth asking, because as you found the problem, you would have investigated exactly what is going on.

    I don't think this is worth the overhead to try to write test coverage, so I will merge as is.

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 8
    last update almost 2 years ago
    229 pass
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 8
    last update almost 2 years ago
    229 pass
  • Status changed to Fixed almost 2 years ago
  • πŸ‡¬πŸ‡§United Kingdom jonathan1055

    Committed and fixed. Thank you.

  • πŸ‡¨πŸ‡¦Canada m4olivei Grimsby, ON

    Yay! Thanks for the quick turn around jonathan1055. Can I ask what your feel is for when your next release cut will be? Seems like a fair bit of thing have been building since the last RC

    https://git.drupalcode.org/project/scheduler/-/compare/2.0.0-rc8...2.x

  • πŸ‡¬πŸ‡§United Kingdom jonathan1055

    I'm going to finish πŸ› Don't run hook_modules_installed during config install Fixed then make a new release immediately.

    You are right that there have been quite a few commits, but many are "behind the scenes" such as coding standards, tugboat, travis, gitlab-CI. There are not that many actual major code changes. So I'm undeciced whether to make another release candidate (rc9) or just release 2.0.

    I think it would be better to have rc9 live for a few weeks, before the full 2.0. What's your view on that?

  • πŸ‡¨πŸ‡¦Canada m4olivei Grimsby, ON

    You are right that there have been quite a few commits, but many are "behind the scenes" such as coding standards, tugboat, travis, gitlab-CI. There are not that many actual major code changes. So I'm undeciced whether to make another release candidate (rc9) or just release 2.0.

    I think it would be better to have rc9 live for a few weeks, before the full 2.0. What's your view on that?

    Ah, right. I just read through the full diff. Looks light and safe to me from a static review perspective. RC8 has been in the wild since Nov 2022. My $0.02 CAD would be to just go for it, cut the 2.0.0. Release notes for the RC8 stated:

    The final rc release before 2.0

    Totally up to you, you're clearly a solid maintainer, I'd trust and respect your decision.

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

  • Status changed to Fixed over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States matthand Riverdale Park, Maryland

    We are interested in seeing this fix released for Scheduler module. Is it possible to make a new release candidate? What do you need help with?

  • πŸ‡¬πŸ‡§United Kingdom jonathan1055

    Hi matthand,
    I have just committed the fix to the final 2.0 blocker πŸ› Don't run hook_modules_installed during config install Fixed and released Scheduler 2.0.0 β†’

    I appreciate the offer of help, thank you. There are plenty of 2.x issues to work on β†’ and I'm ok with making a 2.0.1 release soon if there are some major things that need urgent fixing.

  • πŸ‡¬πŸ‡§United Kingdom jonathan1055

    I have just found that this change causes a problem for taxonomy terms when initialising a new site, eg in Tugboat build, and the outcome is that the Scheduler input fields remain hidden. For some reason, $form_display->isNew() is true for the vocabulary default display.

    entityTypeId => taxonomy_term
    bundle_id => tags
    display_mode => default
    form_display => stdClass Object
    (
        [__CLASS__] =&gt; Drupal\Core\Entity\Entity\EntityFormDisplay
        [entityTypeId:protected] => entity_form_display
        [enforceIsNew:protected] => 1
        [typedData:protected] => 
    

    At the same point in the site build, the node form, product and media forms all have isNew() false. I don't know why Taxonomy is different.

Production build 0.71.5 2024