Undefined array key “className” in processBlock()

Created on 4 June 2024, 22 days ago
Updated 20 June 2024, 6 days ago

Problem/Motivation

It seems that the $block_attributes array does not contain the className key in certain cases, such as when using a custom Drupal Views block

Steps to reproduce

Using bad theming I assume and using custom drupal views block, I get:

Drupal\gutenberg\BlockProcessor\DrupalBlockProcessor->processBlock() (line 93 of modules/contrib/gutenberg/src/BlockProcessor/DrupalBlockProcessor.php).

Proposed resolution

modify the code to check for the existence of the key before accessing it.

      // Add extra CSS classes if available.
      if ($block_attributes['className']) {
        $extra_classes = preg_split('/\s+/', $block_attributes['className']);
        foreach ($extra_classes as $class) {
          if (!empty($class)) {
            $render['content']['#attributes']['class'][] = $class;
          }
        }
      }

Remaining tasks

Review and merge

User interface changes

None

API changes

None

Data model changes

None

🐛 Bug report
Status

Fixed

Version

3.0

Component

Code

Created by

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

Merge Requests

Comments & Activities

Production build 0.69.0 2024