Problem/Motivation

When the Views exposed filters are rendered as a block any attributes on the form are rendered as attributes of the block div instead of the form itself.

For instance when the exposed form is rendered in a block, the block div gets the class "views-exposed-form" that should be on the form (when the exposed form is output within the view itself, the class is set on the form element.

We found this issue when we wanted to add a novalidate attribute on an exposed form (using a form alter) to disable HTML5 validation, because of its accessibility issues. This lead to invalid HTML, because the attribute was added to the parent block div element.

Steps to reproduce

Create a view with an exposed form rendered as a block and check that the class="views-exposed-form" is rendered as an attribute on the parent block div element instead of on the form element.

Proposed resolution

Change the render array that ViewsExposedFilterBlock::build() returns and put the form render array one level lower in the array:

From:

  $output = $this->view->display_handler->viewExposedFormBlocks();

To:

    $output['form'] = $this->view->display_handler->viewExposedFormBlocks();

Remaining tasks

None

User interface changes

None

API changes

None

Data model changes

None

Release notes snippet

Since the class of the form is now incorrectly rendered on the parent block div element, there might be issues with CSS selectors that are not correct anymore?

Comments

Marty2081 created an issue. See original summary.

marty2081’s picture

Status: Active » Needs review
StatusFileSize
new819 bytes

And here is a patch.

marty2081’s picture

Status: Needs review » Closed (duplicate)

Apparantly this is a wider issue in the BlockViewBuilder: #2486267: Attributes of a block content are applied to block itself. So closing this issue as a duplicate