Problem/Motivation

\Drupal\views\Plugin\views\HandlerBase exposes these methods, allowing an "extra options" form

public function buildExtraOptionsForm(&$form, FormStateInterface $form_state) {}
public function validateExtraOptionsForm($form, FormStateInterface $form_state) {}
public function submitExtraOptionsForm($form, FormStateInterface $form_state) {}

Extra Options Form validation errors will prevent the form form being submitted, but, the errors are not displayed anywhere. This is confusing for site builder because they might think that the submit has been successful.

In core there are only 3 filters using this:

  1. \Drupal\taxonomy\Plugin\views\filter\TaxonomyIndexTid
  2. \Drupal\taxonomy\Plugin\views\filter\TaxonomyIndexTidDepth
  3. \Drupal\views\Plugin\views\filter\EntityReference

Currently, all extra options form elements in all of the above filter plugins are configured to always pass form validation. Therefore, there is no way to trigger a form validation error in core and manually test for this bug, without a patch to change this code.

This bug was first detected by claudiu.cristea while working on #2784233-129: Allow multiple vocabularies in the taxonomy filter. In this issue's MR a new required vids form element is being added to TaxonomyIndexTid::buildExtraOptionsForm. If that element is left empty, the form is not submitted (as expected) but no error messages are displayed anywhere.

Further more, this bug was also experienced by scott_euser in the development of the EntityReference filter (which is now in core) (see #2429699-486: Add Views EntityReference filter to be available for all entity reference fields, specifically the section titled Conditionally required fields within selection hanlders in that comment).

The EntityReference filter handler displays the selected Entity Reference selection handler's options within the Extra Options form. If any of those form fields fail validation, the form doesn't submit (good) but no error messages are displayed (bad). There is an outstanding todo in EntityReference::validateRequired referencing this issue.

Steps to reproduce

As mentioned above, a patch file is needed to manually test for this bug.

The patch file drupal-validation-of-errors-in-extra-options-muted-3163740-9.patch will modify the TaxonomyIndexTid filter to remove the default value Vocabulary field and sets the field to required. This will enable the Vocabulary form field to be left empty to trigger a validation error.

Follow the instructions outlined in comment #8 below.

Proposed resolution

Make the validation error displayable but adding the following code to ConfigHandlerExtra::validateForm to instruct ajax to re-render the form. The same code can already be found in \Drupal\views_ui\Form\Ajax\ConfigHandler::validateForm and \Drupal\views_ui\Form\Ajax\Display::validateForm.

    if ($form_state->getErrors()) {
      $form_state->set('rerender', TRUE);
    }

Remaining tasks

  • Provide clear steps to reproduce this issue

User interface changes

Show the validation error to the user.

API changes

None.

Data model changes

None.

Release notes snippet

None.

Issue fork drupal-3163740

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

claudiu.cristea created an issue. See original summary.

larowlan’s picture

Issue summary: View changes
codersukanta’s picture

I would be helpfull if you add steps to reproduce in issue summary.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev
tinto’s picture

Issue summary: View changes
Status: Active » Postponed (maintainer needs more info)
Issue tags: +Bug Smash Initiative, +Needs steps to reproduce

It's been 2 years since the request for steps to reproduce/test this issue, so I am changing the status to Postponed (maintainer needs more info) and adding 'Add steps to reproduce' to the remaining tasks in the issue summary.

I second #3 in that it would really help to be able to resolve this issue (or push it forward). If anyone can provide complete steps to reproduce the issue (starting from "Install Drupal core"), document those steps in the issue summary and set the issue status back to "Active".

If this issue summary does not receive any additional information in the coming months, I suggest someone other than me may consider closing this issue.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

scott_euser’s picture

Version: 9.4.x-dev » 9.5.x-dev
Status: Postponed (maintainer needs more info) » Active
Issue tags: -Needs steps to reproduce
StatusFileSize
new3.74 MB

Attached patch allows us to reproduce this in core by changing the vocabulary selection to be required and removing the default value.

  • Expected: you must select a vocabulary and if you do not, an error message is shown
  • Actual: you can click apply and continue to the next step without the form being validated

Steps to reproduce:

  1. Apply patch so there is sample code that should result in validation errors
  2. Use 'standard install' so Article, Tags, and reference field from Article to Tags exists
  3. Attempt to add tags filter as per screencast below to /admin/structure/views/view/content
  4. Click apply button without selecting a vocabular: no validation error is shown

Screencast of above described steps to reproduce.

scott_euser’s picture

...and the patch sorry!

scott_euser’s picture

Note that this stops https://www.drupal.org/project/drupal/issues/2429699#comment-14623083 from being properly implemented

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

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

tame4tex’s picture

Assigned: Unassigned » tame4tex
tame4tex’s picture

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

So this ended up being a simple fix. ConfigHandlerExtra::validateForm was missing the code to instruct ajax to re-render the form so that error messages are included. Specifically:

    if ($form_state->getErrors()) {
      $form_state->set('rerender', TRUE);
    }

I have added a test and fixed this bug. I have also updated the IS with the steps to reproduce and the proposed resolution.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative

Left 2 small comments on the MR.

If you are another contributor eager to jump in, please allow the previous poster(s) at least 48 hours to respond to feedback first, so they have the opportunity to finish what they started!

tame4tex’s picture

Status: Needs work » Needs review

Thank for the review smustgrave!

Resolved one comment and added justification for the new test class in a reply on the other comment. Back to NR.

smustgrave’s picture

Status: Needs review » Needs work

So I tried to follow the steps in #8 but the tags field is using radio buttons so something is always selected. Are there other steps?

tame4tex’s picture

Issue summary: View changes
tame4tex’s picture

Issue summary: View changes
Status: Needs work » Needs review

@smustgrave I have updated the IS which explains and highlights the need for the patch file to enable manual testing. I have also added extra details on where this bug is being encountered.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new45.05 KB

Okay I am seeing if I hack that views module file that errors aren't appearing.
With the MR I see

MR

All threads have already been resolved so believe this one is good to go.

quietone’s picture

Component: views.module » views_ui.module

All the changes are in views_ui module, so changing component.

  • catch committed a580f549 on 11.x
    Issue #3163740 by scott_euser, claudiu.cristea, tame4tex, smustgrave:...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 11.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.

Status: Fixed » Closed (fixed)

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