Problem/Motivation
I admit this is a very specific problem, but when you have a Views exposed form in a block and set the ARIA "role" attribute on the form then any page displaying that block will return a TypeError like this:
TypeError: mb_strtolower(): Argument #1 ($string) must be of type string, array given in mb_strtolower() (line 225 of core/lib/Drupal/Component/Utility/Html.php).
Steps to reproduce
- Create a page view with exposed filters and configure it to have the exposed form in a block.
- Place the block.
- Alter the exposed form in some way to place the
"role"attribute on it – i.e., like this:$form['#attributes']['role'] = 'search'; - Navigate to any page displaying the exposed form block.
- You will get an error page with a
TypeErroror a WSoD, depending on your configuration.
To quickly see the problem, check out this merge request where a test fails like this.
Proposed resolution
template_preprocess_block() should be fixed to handle render arrays in $variables['label'] correctly.
Remaining tasks
Decide which code is correct and which is buggy.Create an MR for fixing the problem.Create a regression test.- Merge the MR.
User interface changes
None.
Introduced terminology
None.
API changes
None.
Data model changes
None.
Release notes snippet
N/A
Issue fork drupal-3503878
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
Comment #2
drunken monkeyComment #3
quietone commentedComment #4
niranjan_panem commentedI tested the issue, views-pages and exposed forms are working fine in drupal, but not able to reproduce the issue.
Comment #5
niranjan_panem commentedComment #6
bnjmnmGiven that I've had to reopen several issues incorrectly closed by @niranjan_panem and
Doesn't provide enough detail to indicate the steps to reproduce were followed, this may not have received the due diligence required to justify setting this to Closed (cannot reproduce)
Comment #9
riyas_nr commentedI have implemented a fix to ensure that when
$variables['label']is an array, it gets rendered into a string before assigning it totitle_attributes['id']. This prevents theTypeErrorwhen setting form attribute$form['#attributes']['role'] = 'search';Additionally, I have added a PHPUnit test to verify this.
Comment #10
riyas_nr commentedComment #11
smustgrave commentedIssue summary needs some work as the proposed solution is not flushed out.
Left a comment on the MR.
Comment #12
riyas_nr commentedMoved the Views exposed filter test to the Search integration test file, as this test verifies that when the
searchrole is assigned to the Views exposed form, thearia-describedbyattribute is correctly set without aTypeError. This issue occurs only when the Views exposed form label is rendered as an array.As per the MR comment, I have also added test coverage for the Block module by adding the role attribute for a standard block and verifying the normal label scenario.
Comment #13
drunken monkey@riyas_nr: This looks great to me, thanks a lot for your work on this! Setting to RTBC.
I amended the “Proposed resolution” section of the IS.
Comment #14
catchCouple of comments on the MR.