Unable to get/set form_state values in SelectionPluginBase::validateConfigurationForm when called from EntityReference::validateExtraOptionsForm

Created on 23 August 2025, 15 days ago

Problem/Motivation

Any child class of \Drupal\Core\Entity\EntityReferenceSelection\SelectionPluginBase that implements SelectionPluginBase::validateConfigurationForm cannot get or set form_state values when called in a Views Entity Reference Filter context (called from \Drupal\views\Plugin\views\filter\EntityReference::validateExtraOptionsForm).

The issue stems from the SubformState that is created in EntityReference::validateExtraOptionsForm. \Drupal\views_ui\Form\Ajax\ConfigHandlerExtra::validateForm calls EntityReference::validateExtraOptionsForm and provides the form and form_state for that method. The issue is it is only providing part of the form array, but the full form_state object. This means the SubformState object is not being created with the correct parent form. So #parents is not correct and does not match the form_state values array, thus setValue() and getValue() do not work.

Steps to reproduce

TBD

Proposed resolution

OPTION 1 (Preferred)

  1. Refactor ConfigHandlerExtra::validateForm to create a SubformState which is passed in to EntityReference::validateExtraOptionsForm
  2. Then EntityReference::validateExtraOptionsForm will be able to create a valid SubformState to pass through to SelectionPluginBase::validateConfigurationForm

Pros:

Cons:

  • This will break BC of existing implementations of \Drupal\views\Plugin\views\HandlerBase::validateExtraOptionsForm that are expecting a specific form_state values array structure. EntityReference::validateExtraOptionsForm is the only core implementation of this method, but there could be contrib/custom modules that implement it.

OPTION 2

  1. Refactor EntityReference::validateExtraOptionsForm to pass through the full form_state object to SelectionPluginBase::validateConfigurationForm, instead of a SubformState.

Pros:

  • Fixes the bug with minimum risk of BC issues. It is still a BC break on SelectionPluginBase::validateConfigurationForm, but given it doesn’t work anyway I would assume it is acceptable.

Cons:

  • Does not follow the recommended practice of passing in a SubformState to PluginFormInterface::validateConfigurationForm

Remaining tasks

  1. Add steps to manually reproduce bug
  2. Add automated testing for bug
  3. Community feedback and decision on preferred solution
  4. Contribute fix

User interface changes

N/A

Introduced terminology

N/A

API changes

TBD

Data model changes

N/A

Release notes snippet

TBD

🐛 Bug report
Status

Active

Version

11.0 🔥

Component

views_ui.module

Created by

🇨🇦Canada tame4tex

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @tame4tex
  • 🇨🇦Canada tame4tex

    The BC Policy states:

    While the Render and Form APIs themselves are stable, the exposed data structures used to build and cache pages and forms are not. We will change these structures where necessary to make usability improvements or add features in minor versions. This means alter hook implementations may need to be updated.

    So, it looks like OPTION 1 may not break BC, therefore, I am going to proceed with this option for now.

    Thanks to @joachim on slack for providing me with the friendly BC Policy reminder.

  • 🇺🇸United States nicxvan

    Well to be clear, it still breaks BC.

    It is more that core reserves the right to break BC in those cases but we still make best effort to provide the update on a non breaking way.

    It's generally weighed against how disruptive the change will be. E.g. can you search contrib code and see how many modules will be affected?

    How easy is the fix? The easier for contrib or custom to update especially in a way that supports multiple versions of core the more likely.

    Finally, how important is the feature or bug fix?

    Answering those questions will help determine the path to take.

    You can always ask the views maintainers too, I've tagged this issue, but paying on the core development channel in slack will likely get your questions answered faster.

  • 🇨🇦Canada tame4tex

    @nicxvan Thank you for the detailed response and clarification!

    A code search revealed the Option 1 change would break two contrib modules:

    1. taxonomy_machine_name (SearchApiTaxonomyMachineName::validateExtraOptionsForm)
    2. mapkit (MapkitLocationFilter::validateExtraOptionsForm)

    Both methods would require a relatively straightforward fix to account for the new form state values root, but would need a new version that only supported the 11.x version this was committed to. Supporting multiple 11.x versions would require in a more complex (and most likely undesirable) fix as two different form state values arrays would need to be supported.

    MapkitLocationFilter::validateExtraOptionsForm would also need to remove their workaround to get the correct parent form when creating the SubformState.

    The MapkitLocationFilter::validateExtraOptionsForm code gave me a better idea for the Option 2 fix. EntityReference::validateExtraOptionsForm simply needs to use the complete form obtained from FormStateInterface::getCompleteForm, when constructing the SubformState.

    So on further reflection maybe Option 2 is a better fix for now with the consideration for Option 1 in 12.x?

    I am going to update the IS with these findings. Both options are relatively straight forward to implement so I am going to create a branch and MR for both, which may help in providing context when deciding which option is best.

    I will definitely reach out to views maintainers on slack for feedback also.

  • 🇨🇦Canada tame4tex

    Updated IS with the latest findings and added steps to manually reproduce the error.

  • 🇨🇦Canada tame4tex

    I have opened two draft Merge Requests for review and feedback on the proposed options for resolution.

    MR !13089 - OPTION 1

    MR !13090 - OPTION 2

  • Pipeline finished with Failed
    11 days ago
    Total: 652s
    #582474
  • Pipeline finished with Failed
    11 days ago
    Total: 645s
    #582475
  • 🇨🇦Canada tame4tex

    The following bug 🐛 PHP warning when changing “Reference method” in Views EntityReference filter extra settings Active is causing the new test to fail in both draft MRs. I have added temporary code based on the fix from this issue to enable the tests to pass and not distract from further development on this issue.

    Issue #3542769 will therefore need to be merged in before this one.

  • 🇨🇦Canada tame4tex

    Setting to Needs Review to get feedback on the proposed resolution options.

  • Pipeline finished with Failed
    11 days ago
    Total: 1285s
    #582487
  • Pipeline finished with Failed
    11 days ago
    Total: 1313s
    #582486
  • The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

    This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

Production build 0.71.5 2024