Problem/Motivation
This is my first time using this module. Installed version 2.0.0-alpha3 on Drupal 10.2.6
I tried to create a Site Setting Type without a Group label, and when I save it gives a WSOD error:
The website encountered an unexpected error. Try again later.
TypeError: reset(): Argument #1 ($array) must be of type array, null given in reset() (line 203 of modules/contrib/site_settings/src/Form/SiteSettingEntityTypeForm.php).
Steps to reproduce
- Go to link
/admin/structure/site_setting_entity_type - click Add Site Setting Type button
- Label field (marked required) --- enter any label
- Create a new "Group" label (not marked required) --- leave blank
- Click Save button at bottom
Proposed resolution
It seems the resolution here depends whether or not the group label field is intended to be a required field...
from reading the documentation, a group label seemed optional and I didn't think I needed it for my use case...
However, if all site settings types should be part of a group, well then simply rendering that form field as required would fix this issue, since the error clears up when I enter a group label in that field.
Issue fork site_settings-3445275
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:
- 3445275-validate-form
changes, plain diff MR !28
- 3445275-group-label-required
changes, plain diff MR !24
Comments
Comment #2
aaron.ferris commentedI could be wrong, but looking at the code following the error it looks as though
new_groupshould be required.$new_group->set('id', $this->generateMachineName($new_group->label()));The alternate to this would be of course to only run this block of code if new_group is populated which would avoid the WSOD, but not sure of any other consequences if we go this route.
Comment #4
aaron.ferris commentedComment #5
scott_euser commentedThanks both! Unfortunately it's a bit more complicated than that - new group should only be conditionally required if an existing group is not chosen. So we need to implement the validate method of form base.
Ideally we should also extend the save method on the entity itself to throw an exception if someone attempts to create a Site Setting entity programmatically without a Group.
Comment #9
scott_euser commentedAdded the validation part of this, but see also related #3446920: WSOD after upgrading from 2.0.0-alpha2 to 2.0.0-alpha3: Drupal\site_settings\Plugin\SiteSettingsLoader\FlattenedSiteSettingsLoader::groupKey(): Argument #1 ($group) must be of type string, null given. Thanks!