Undefined array key “className” in processBlock()

Created on 4 June 2024, 8 months ago
Updated 20 July 2024, 6 months 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

  • Issue created by @doxigo
  • Status changed to Needs review 8 months ago
  • Pipeline finished with Success
    8 months ago
    Total: 254s
    #190518
  • 🇳🇴Norway vegardjo

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

  • Status changed to RTBC 8 months ago
  • 🇳🇴Norway vegardjo

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

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

  • 🇺🇸United States Dave Kopecek

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

  • Pipeline finished with Success
    7 months ago
    Total: 343s
    #197104
    • doxigo committed 6f173ec4 on 3.x
      Issue #3452390: Check for className key existence in...
  • Status changed to Fixed 7 months ago
  • 🇵🇹Portugal marcofernandes

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

  • Status changed to RTBC 7 months ago
  • 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...
  • Status changed to Fixed 7 months ago
  • 🇵🇹Portugal marcofernandes

    @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.

  • 🇳🇴Norway eiriksm Norway

    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?

  • 🇩🇪Germany szeidler Berlin

    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...
  • Pipeline finished with Success
    6 months ago
    #229753
  • Automatically closed - issue fixed for 2 weeks with no activity.

  • Pipeline finished with Failed
    6 months ago
    Total: 181s
    #232210
  • Pipeline finished with Success
    6 months ago
    Total: 663s
    #233760
  • Pipeline finished with Canceled
    6 months ago
    Total: 162s
    #233812
  • Pipeline finished with Failed
    6 months ago
    Total: 610s
    #233806
  • Pipeline finished with Success
    6 months ago
    Total: 1444s
    #233815
  • Pipeline finished with Success
    6 months ago
    Total: 174s
    #235258
  • Pipeline finished with Success
    6 months ago
    Total: 170s
    #236538
  • Pipeline finished with Success
    6 months ago
    #236542
  • Pipeline finished with Failed
    6 months ago
    Total: 2090s
    #238615
  • Pipeline finished with Failed
    6 months ago
    #238722
  • Pipeline finished with Failed
    6 months ago
    Total: 1405s
    #238731
  • Pipeline finished with Failed
    6 months ago
    #238782
  • Pipeline finished with Success
    6 months ago
    #238808
  • Pipeline finished with Success
    6 months ago
    Total: 867s
    #238825
  • Pipeline finished with Success
    6 months ago
    Total: 311s
    #242925
  • Pipeline finished with Success
    6 months ago
    Total: 312s
    #242927
  • Pipeline finished with Failed
    5 months ago
    Total: 399s
    #247051
  • Pipeline finished with Failed
    5 months ago
    #247584
  • Pipeline finished with Failed
    5 months ago
    Total: 532s
    #247589
  • Pipeline finished with Failed
    5 months ago
    Total: 342s
    #247651
  • Pipeline finished with Failed
    5 months ago
    #247667
  • Pipeline finished with Failed
    5 months ago
    #247681
  • Pipeline finished with Failed
    5 months ago
    #247852
  • Pipeline finished with Failed
    5 months ago
    Total: 322s
    #248985
  • Pipeline finished with Success
    5 months ago
    Total: 323s
    #248998
  • Pipeline finished with Canceled
    5 months ago
    Total: 255s
    #249187
  • Pipeline finished with Failed
    5 months ago
    Total: 315s
    #249192
  • Pipeline finished with Failed
    5 months ago
    Total: 316s
    #249217
  • Pipeline finished with Success
    5 months ago
    Total: 319s
    #249234
  • Pipeline finished with Canceled
    5 months ago
    Total: 72s
    #251442
  • Pipeline finished with Canceled
    5 months ago
    Total: 224s
    #251443
  • Pipeline finished with Canceled
    5 months ago
    Total: 117s
    #251447
  • Pipeline finished with Success
    5 months ago
    Total: 307s
    #251448
  • Pipeline finished with Success
    5 months ago
    Total: 22866s
    #251757
  • Pipeline finished with Success
    5 months ago
    #252470
  • Pipeline finished with Success
    5 months ago
    #252626
  • Pipeline finished with Failed
    5 months ago
    Total: 1346s
    #252769
  • Pipeline finished with Success
    5 months ago
    Total: 534s
    #252787
  • Pipeline finished with Success
    5 months ago
    Total: 382s
    #252801
  • Pipeline finished with Failed
    3 months ago
    Total: 693s
    #304476
  • Pipeline finished with Success
    3 months ago
    Total: 349s
    #304842
  • Pipeline finished with Success
    3 months ago
    Total: 259s
    #304854
  • Pipeline finished with Success
    3 months ago
    Total: 181s
    #319099
  • Pipeline finished with Success
    3 months ago
    Total: 284s
    #319106
  • Pipeline finished with Failed
    3 months ago
    Total: 597s
    #324435
  • Pipeline finished with Failed
    3 months ago
    Total: 520s
    #324453
  • Pipeline finished with Failed
    3 months ago
    Total: 923s
    #324480
  • Pipeline finished with Failed
    3 months ago
    Total: 992s
    #324524
  • Pipeline finished with Failed
    3 months ago
    Total: 292s
    #326656
  • Pipeline finished with Skipped
    about 2 months ago
    #348414
  • Pipeline finished with Skipped
    about 1 month ago
    #366065
  • Pipeline finished with Success
    26 days ago
    Total: 340s
    #377665
Production build 0.71.5 2024