Problem/Motivation
Setting or changing the Reference method in any Entity reference Views filter via the filter’s Settings link (Configure extra settings) triggers a PHP warning during submit:
Warning: Undefined array key "[ref_type]" in Drupal\views\Plugin\views\filter\EntityReference->submitExtraOptionsForm()
This bug is preventing any Functional Test that does this from passing e.g. #3542714: Unable to get/set form_state values in SelectionPluginBase::validateConfigurationForm when called from EntityReference::validateExtraOptionsForm
Steps to reproduce
- Set up a fresh Drupal 11 dev site (includes Article and Page content types by default).
- Add an Entity reference field on the Page content type that references Article nodes.
- Enable the
views_test_entity_referencetest module (in core) or alternatively install the
Views Core Entity Reference contributed module.
This ensures theviewsDataAlter()hook exposes the new EntityReference filter. - Edit the default Content view provided by core.
- Add the new entity reference field as a filter:
- Select the Default reference method.
- Restrict to the Article content type.
- Save the view.
- Check error logs and PHP warning is present:
Warning: Undefined array key "reference_default:node" in Drupal\views\Plugin\views\filter\EntityReference->submitExtraOptionsForm() - Re-edit the filter. Click the filter’s Settings link to open Configure extra settings.
- Change the Reference method to “Views: Filter by an entity reference view”,
then click Apply and save the view. - Check error logs and PHP warning is present:
Warning: Undefined array key "reference_views" in Drupal\views\Plugin\views\filter\EntityReference->submitExtraOptionsForm()
Proposed resolution
Refactor \Drupal\views\Plugin\views\filter\EntityReference::submitExtraOptionsForm to remove the code that sets $this->options['sub_handler_settings'] which is causing the php warning.
The setting of this options property array key is unnecessary as \Drupal\views_ui\Form\Ajax\ConfigHandlerExtra::submitForm will handle this correctly.
Remaining tasks
- Merge request review
User interface changes
None
Introduced terminology
None
API changes
None
Data model changes
Node
Release notes snippet
N/A
Issue fork drupal-3542769
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:
- 3542769-php-warning-when
changes, plain diff MR !13079
Comments
Comment #2
tame4tex commentedSo it looks like this PHP warning is also thrown when adding an Entity Reference filter and setting the Reference method for the first time. I have updated the IS to reflect this.
Comment #4
tame4tex commentedI have opened MR 13079 that contains testing for the bug and the fix.
Ready for review!
Comment #5
tame4tex commentedThis bug is preventing Functional Test from passing that set or change the Reference method in any Entity reference Views filter e.g. #3542714: Unable to get/set form_state values in SelectionPluginBase::validateConfigurationForm when called from EntityReference::validateExtraOptionsForm.
Comment #7
smustgrave commentedHad to rebase for the test-only job to run https://git.drupalcode.org/issue/drupal-3542769/-/jobs/6399689
Which shows the coverage for the change being added.
Trying to replicate following the steps, not using the contrib module though, I believe I'm able to see it. The change to submitExtraOptionsForm makes sense to me.
LGTM
Comment #8
longwaveBackported down to 10.5.x as an eligible bug fix.
Committed and pushed a7b619c813e to 11.x and acd99cccc62 to 11.2.x and cb93ef7747a to 10.6.x and ad75505b110 to 10.5.x. Thanks!
Comment #15
tame4tex commentedGreat! Thanks @smustgrave and @longwave for getting this committed.