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.
Issue fork scheduler-3359790
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
Comment #2
m4oliveiComment #4
m4oliveiSee merge request.
Comment #5
m4oliveiComment #7
jonathan1055 commentedHi 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:
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.
Comment #8
jonathan1055 commentedI've sucessfully replicated the probelm, and with the suggested fix it is solved.
Comment #9
m4oliveiSure 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:
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, and sometimes (as in our case),
$form_display->isNew() === TRUE. In the update hook, whensave()iscalled, 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?
Comment #10
jonathan1055 commentedYes 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.
Comment #12
jonathan1055 commentedCommitted and fixed. Thank you.
Comment #13
m4oliveiYay! 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
Comment #14
jonathan1055 commentedI'm going to finish #3336108: Don't run hook_modules_installed during config install 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?
Comment #15
m4oliveiAh, 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:
Totally up to you, you're clearly a solid maintainer, I'd trust and respect your decision.
Comment #17
matthandWe 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?
Comment #18
jonathan1055 commentedHi matthand,
I have just committed the fix to the final 2.0 blocker #3336108: Don't run hook_modules_installed during config install and released Scheduler 2.0.0
I appreciate the offer of help, thank you. Here are the 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.
Comment #19
jonathan1055 commentedI 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.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.
Comment #20
jonathan1055 commentedOpened #3454624: Scheduler fields for Taxonomy Terms remain hidden when site is configured by script (local drush or Tugboat preview )