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

  1. Create a page view with exposed filters and configure it to have the exposed form in a block.
  2. Place the block.
  3. Alter the exposed form in some way to place the "role" attribute on it – i.e., like this: $form['#attributes']['role'] = 'search';
  4. Navigate to any page displaying the exposed form block.
  5. You will get an error page with a TypeError or 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

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

drunken monkey created an issue. See original summary.

drunken monkey’s picture

Issue summary: View changes
quietone’s picture

Version: 11.1.x-dev » 11.x-dev
niranjan_panem’s picture

I tested the issue, views-pages and exposed forms are working fine in drupal, but not able to reproduce the issue.

niranjan_panem’s picture

Status: Active » Closed (cannot reproduce)
bnjmnm’s picture

Status: Closed (cannot reproduce) » Active

Given that I've had to reopen several issues incorrectly closed by @niranjan_panem and

I tested the issue, views-pages and exposed forms are working fine in drupal, but not able to reproduce the issue.

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)

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

riyas_nr’s picture

I have implemented a fix to ensure that when $variables['label'] is an array, it gets rendered into a string before assigning it to title_attributes['id']. This prevents the TypeError when setting form attribute $form['#attributes']['role'] = 'search';

Additionally, I have added a PHPUnit test to verify this.

riyas_nr’s picture

Status: Active » Needs review
smustgrave’s picture

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

Issue summary needs some work as the proposed solution is not flushed out.

Left a comment on the MR.

riyas_nr’s picture

Status: Needs work » Needs review

Moved the Views exposed filter test to the Search integration test file, as this test verifies that when the search role is assigned to the Views exposed form, the aria-describedby attribute is correctly set without a TypeError. 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.

drunken monkey’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

@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.

catch’s picture

Status: Reviewed & tested by the community » Needs work

Couple of comments on the MR.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.