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

  1. Set up a fresh Drupal 11 dev site (includes Article and Page content types by default).
  2. Add an Entity reference field on the Page content type that references Article nodes.
  3. Enable the views_test_entity_reference test module (in core) or alternatively install the
    Views Core Entity Reference contributed module.
    This ensures the viewsDataAlter() hook exposes the new EntityReference filter.
  4. Edit the default Content view provided by core.
  5. Add the new entity reference field as a filter:
    • Select the Default reference method.
    • Restrict to the Article content type.
  6. Save the view.
  7. Check error logs and PHP warning is present: Warning: Undefined array key "reference_default:node" in Drupal\views\Plugin\views\filter\EntityReference->submitExtraOptionsForm()
  8. Re-edit the filter. Click the filter’s Settings link to open Configure extra settings.
  9. Change the Reference method to “Views: Filter by an entity reference view”,
    then click Apply and save the view.
  10. 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

Command icon 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

tame4tex created an issue. See original summary.

tame4tex’s picture

Title: PHP warning when changing “Reference method” in Views EntityReference filter extra settings » PHP warning when setting/changing “Reference method” in Views EntityReference filter extra settings
Issue summary: View changes

So 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.

tame4tex’s picture

Assigned: tame4tex » Unassigned
Issue summary: View changes
Status: Active » Needs review

I have opened MR 13079 that contains testing for the bug and the fix.

Ready for review!

tame4tex’s picture

Issue summary: View changes

This 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.

smustgrave made their first commit to this issue’s fork.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative, +Bug Smash Initiative

Had to rebase for the test-only job to run https://git.drupalcode.org/issue/drupal-3542769/-/jobs/6399689

1) Drupal\Tests\views_ui\Functional\FilterEntityReferenceWebTest::testFilterUi
Exception: Warning: Undefined array key "reference_views"
Drupal\views\Plugin\views\filter\EntityReference->submitExtraOptionsForm()() (Line: 367)
/builds/issue/drupal-3542769/core/lib/Drupal/Core/Test/HttpClientMiddleware/TestHttpClientMiddleware.php:55
/builds/issue/drupal-3542769/vendor/guzzlehttp/promises/src/Promise.php:209
/builds/issue/drupal-3542769/vendor/guzzlehttp/promises/src/Promise.php:158
/builds/issue/drupal-3542769/vendor/guzzlehttp/promises/src/TaskQueue.php:52
/builds/issue/drupal-3542769/vendor/guzzlehttp/promises/src/Promise.php:251
/builds/issue/drupal-3542769/vendor/guzzlehttp/promises/src/Promise.php:227
/builds/issue/drupal-3542769/vendor/guzzlehttp/promises/src/Promise.php:272
/builds/issue/drupal-3542769/vendor/guzzlehttp/promises/src/Promise.php:229
/builds/issue/drupal-3542769/vendor/guzzlehttp/promises/src/Promise.php:69
/builds/issue/drupal-3542769/vendor/guzzlehttp/guzzle/src/Client.php:189
/builds/issue/drupal-3542769/core/tests/Drupal/Tests/DrupalTestBrowser.php:139
/builds/issue/drupal-3542769/vendor/symfony/browser-kit/AbstractBrowser.php:378
/builds/issue/drupal-3542769/vendor/symfony/browser-kit/AbstractBrowser.php:298
/builds/issue/drupal-3542769/vendor/behat/mink-browserkit-driver/src/BrowserKitDriver.php:718
/builds/issue/drupal-3542769/vendor/behat/mink-browserkit-driver/src/BrowserKitDriver.php:494
/builds/issue/drupal-3542769/vendor/behat/mink/src/Element/NodeElement.php:176
/builds/issue/drupal-3542769/vendor/behat/mink/src/Element/NodeElement.php:186
/builds/issue/drupal-3542769/core/tests/Drupal/Tests/UiHelperTrait.php:112
/builds/issue/drupal-3542769/core/modules/views_ui/tests/src/Functional/FilterEntityReferenceWebTest.php:108
ERRORS!

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

longwave’s picture

Version: 11.x-dev » 10.5.x-dev
Status: Reviewed & tested by the community » Fixed

Backported 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!

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.

  • longwave committed ad75505b on 10.5.x
    Issue #3542769 by tame4tex, smustgrave: PHP warning when setting/...

  • longwave committed cb93ef77 on 10.6.x
    Issue #3542769 by tame4tex, smustgrave: PHP warning when setting/...

  • longwave committed acd99ccc on 11.2.x
    Issue #3542769 by tame4tex, smustgrave: PHP warning when setting/...

  • longwave committed a7b619c8 on 11.x
    Issue #3542769 by tame4tex, smustgrave: PHP warning when setting/...

tame4tex’s picture

Great! Thanks @smustgrave and @longwave for getting this committed.

Status: Fixed » Closed (fixed)

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