Problem/Motivation
If you have no bundle for a entity type created in your Drupal instance, you can't add or edit a view mode.
TypeError: array_keys(): Argument #1 ($array) must be of type array, null given in array_keys() (line 119 of /core/modules/field_ui/src/Form/EntityDisplayModeFormBase.php).
The EntityDisplayModeFormBase class expects at minimum one bundle per entity type.
This behavior was introduced by #3359240: Enable bundle selection when a new view mode is created
Steps to reproduce
- Install Drupal
- Delete all node bundles if present
- Try to add a new view mode for content
- Observe the watchdog log for the given error message
Proposed resolution
Add a defense, so the form could be rendered without a bundle.
Add a test.
Remaining tasks
User interface changes
Maybe we could hide the bundle selection form element in case no bundle is present.
Introduced terminology
API changes
Data model changes
Release notes snippet
Comments
Comment #3
sunlixI've added an easys defense to prevent the add/edit view mode dialog from not rendering.
In behalf of the UI maybe some maintainer have to commit for hiding the bundles field on the dialog.
If so, we can iterate over this issue, but for now it works as expected and the test proof this.
Comment #4
dcam commentedThank you for reporting this issue and for providing a merge request!
I am increasing the priority to Major, both because it qualifies as a Major bug and because it's now more likely that people will encounter this bug since Core doesn't ship with content types by default anymore.
I've reviewed the MR. The fix is simple enough and I don't have any feedback about it. But while I greatly appreciate that you included a test for this bug, it is a FunctionalJavascript test and that needs some work. FunctionalJavascript tests are expensive and slow to run. The things being done in the test are simple enough (or can be) that there's no reason for it. This could easily be a Functional test, probably even Kernel test which is much cheaper to run. The caveat is that you need to access the form directly,
/admin/structure/display-modes/$display_mode/add/node, rather than clicking through to it via the main view mode list. You'll also need to assert for different text on the page because the title doesn't appear.Comment #5
sunlixThanks for your input.
I have moved the test to a kernel test for lower footprint and faster runtime.
The test currently covers building the view mode form.
We can extend that for form mode form, too. But I think view mode form is enough, due to the fact that both shares the logic via
EntityDisplayModeFormBase::form().Comment #6
dcam commentedThis looks great to me. Thank you for rewriting that test.
Comment #7
catchCommitted/pushed to main, 11.x and 11.4.x, thanks!