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?
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 3263435-2-views_exposed_form_as_block_attributes_on_parent_block_div.patch | 819 bytes | marty2081 |
Comments
Comment #2
marty2081 commentedAnd here is a patch.
Comment #3
marty2081 commentedApparantly 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