Empty extra_class field in custom Parallax Block throws error in core Html.php

Created on 18 April 2023, about 1 year ago

Steps to reproduce

Got to /admin/structure/block/block-content, add a new parallax block. Skip adding an extra class. Activate the block by placing it in any region.

If in settings.php you have set

$config['system.logging']['error_level'] = 'verbose';
// hide|some|all|verbose

this throws a warning whenever the render cache is flushed,
Warning: Array to string conversion in Drupal\Component\Utility\Html::getClass() (line 72 of (...)/web/core/lib/Drupal/Component/Utility/Html.php).

Proposed resolution

Two possible resolutions.
1. Add a (dummy) class. Beware, just a space translates to a dash -.
2. In block--electra-parallax.html.twig check whether the extra class exists by changing to

{%
  set classes = [
    'parallax-block',
    'parallax-' ~ type|clean_class,
  ]
%}
{% if content['#block_content'].field_extra_class.value is not empty %}
  {% set extra_class = content['#block_content'].field_extra_class.value %}
  {% set classes = classes|merge([extra_class|clean_class]) %}
{% endif %}

Please review, thanks.

πŸ› Bug report
Status

Active

Version

3.2

Component

Code

Created by

πŸ‡©πŸ‡ͺGermany upunkt

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024