Keep attributes added to forms rendered in blocks

Created on 4 March 2024, 9 months ago

Problem/Motivation

When some form is rendered in block, for example views exposed filter form or custom block plugin that renders some form, all attributes, that are set to form by $form['#attributes'] are moved from form to block level. Actually it affects all render arrays in blocks, but in my case it is especially signifacant for forms. After update ro 5.0.0-rc1 some forms become unstyled. And also it is very signifacant to have attributes on forms, if you are going to add some custom js functionality to forms. I made an investigation and found that attributes are removed here:
https://git.drupalcode.org/project/context/-/blob/8.x-4.x/src/Plugin/Con...

      foreach (['#attributes', '#contextual_links'] as $property) {
        if (isset($content[$property])) {
          $build[$property] += $content[$property];
          unset($content[$property]);
        }
      }

Steps to reproduce

  1. Add or edit some context
  2. Add or edit blocks reaction
  3. Select some block, that provides form: search block or Views exposed form, or some custom plugin
  4. Save context, open page and check that form rendered in block hasn't any CSS classes

Proposed resolution

Skip processing for forms. Seems that initially it was added to inprove contextual links behavior, but forms usually don't have contextual links.

Remaining tasks

Apply patch

User interface changes

No

API changes

No

Data model changes

No

🐛 Bug report
Status

Active

Version

5.0

Component

Code

Created by

🇧🇾Belarus gun_dose

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

Comments & Activities

Production build 0.71.5 2024