[10.2] ckeditor5_post_update_code_block() throws an error for format using CKE5 but with CKE4 settings

Created on 5 February 2024, 4 months ago
Updated 15 May 2024, 18 days ago

Problem/Motivation

When running Database Updates after a drupal 10.0 to 10.2 upgrade, this error appears:

>  [notice] Update started: ckeditor5_post_update_code_block
>  [warning] Undefined array key "items" ckeditor5.post_update.php:104
>  [error]  TypeError: in_array(): Argument #2 ($haystack) must be of type array, null given in in_array() (line 104 of /web/core/modules/ckeditor5/ckeditor5.post_update.php) #0 /web/core/modules/ckeditor5/ckeditor5.post_update.php(104): in_array('codeBlock', NULL, true)

This is the code in question:

function ckeditor5_post_update_code_block(&$sandbox = []) {
  $config_entity_updater = \Drupal::classResolver(ConfigEntityUpdater::class);
  $config_entity_updater->update($sandbox, 'editor', function (Editor $editor): bool {
    // Only try to update editors using CKEditor 5.
    if ($editor->getEditor() !== 'ckeditor5') {
      return FALSE;
    }
    $settings = $editor->getSettings();
    return in_array('codeBlock', $settings['toolbar']['items'], TRUE);
  });
}

Looks like this can be null: $settings = $editor->getSettings();

Proposed resolution

The script should expect null values and return false in this case.

šŸ› Bug report
Status

Postponed: needs info

Version

11.0 šŸ”„

Component
CKEditor 5Ā  ā†’

Last updated 1 day ago

Created by

šŸ‡©šŸ‡ŖGermany Schoenef Unna

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024