Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 291609

TypeError when having exposed form in block and setting "role" attribute on it

$
0
0

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

The problem is either in template_preprocess_block() or in \Drupal\views\Plugin\Block\ViewsExposedFilterBlock::build(). The former assumes that $variables['label'] is always a string/scalar (when it passes it unchecked to Html::getUniqueId() at the bottom of the function), while the latter sets $output['#title'] to a render array which will apparently make it unchanged to $variables['label'] when rendering the block.

I assume the bug is in template_preprocess_block(), as the render array in $output['#title'] otherwise seems to work fine, that’s why I picked this component.

Remaining tasks

  • Decide which code is correct and which is buggy.
  • Create an MR for fixing the problem.
  • Create a regression test.

User interface changes

None.

Introduced terminology

None.

API changes

None.

Data model changes

None.

Release notes snippet

N/A


Viewing all articles
Browse latest Browse all 291609

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>