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

Issue fork gutenberg-3452390

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

doxigo created an issue. See original summary.

doxigo’s picture

Title: ndefined array key “className” in Drupal\gutenberg\BlockProcessor\DrupalBlockProcessor->processBlock() » Undefined array key “className” in Drupal\gutenberg\BlockProcessor\DrupalBlockProcessor->processBlock()
Issue summary: View changes

doxigo’s picture

Title: Undefined array key “className” in Drupal\gutenberg\BlockProcessor\DrupalBlockProcessor->processBlock() » Undefined array key “className” in processBlock()
Status: Active » Needs review
vegardjo’s picture

This is sadly a regression from #3421059: Render custom classes for dynamic blocks, also present in 2.9, Doxigos (👋) fix should do it.

vegardjo’s picture

Status: Needs review » Reviewed & tested by the community

Tested on 2.9 using this as a patch file: https://git.drupalcode.org/issue/gutenberg-3452390/-/commit/6f173ec402ea... and it solves the problem.

doxigo’s picture

Hey Vegard 😍 long time no see, thanks for the review

dave kopecek’s picture

I can confirm that #6 works for me as well.

  • doxigo committed 6f173ec4 on 3.x
    Issue #3452390: Check for className key existence in...

  • marcofernandes committed 526376e8 on 8.x-2.x
    Issue #3452390: Undefined array key “className” in processBlock()
    
marcofernandes’s picture

Status: Reviewed & tested by the community » Fixed

Backported to 8.x-2.x. Thank you!

doxigo’s picture

Status: Fixed » Reviewed & tested by the community

Hey Marco, this seems to be merged into 3.x and we apparently also have a 3.0.x which is not the default branch but is the tagged branch in the releases. so I assume we need to re-apply the patch to 3.0.x and also change the default branch from 3.x to 3.0.x

Opened the issue again

  • doxigo committed 6f173ec4 on 3.0.x
    Issue #3452390: Check for className key existence in...
marcofernandes’s picture

Status: Reviewed & tested by the community » Fixed

@doxigo Yeah, unfortunately d.o is a bit strict with branches naming/versioning. The idea of having 3.x branch was to avoid managing minor versions. I merged 3.x into 3.0.x and have set 3.0.x back to default.

doxigo’s picture

Lovely, thanks

eiriksm’s picture

Seems like something we should create a new release for? Not pretty to have these notices on a stable release I think.

Also, the fact that we have it shows we are missing test coverage. Can we create a follow up issue for adding test coverage here?

szeidler’s picture

Ideally we would bundle the three issues in a new release, which all could break Gutenberg or parts of it, because of warnings or errors.

  • doxigo committed 6f173ec4 on 4.0.x
    Issue #3452390: Check for className key existence in...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.