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

Workaround is the patch in comment #11.

The fix to prevent this is to complete #2628144: Ensure that ConfigImport is taking place against the same code base

Issue fork drupal-3419203

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

Schoenef created an issue. See original summary.

schoenef’s picture

StatusFileSize
new693 bytes

This patch worked for me:

schoenef’s picture

StatusFileSize
new1.05 KB

Ok, the above patch is for Drpal 10.1, for 10.2 this one should do:

wim leers’s picture

Priority: Major » Minor
Status: Active » Postponed (maintainer needs more info)
Issue tags: +Needs steps to reproduce

Actually,

$settings['toolbar']['items']

can never be NULL 😅

Can you please export your config as it was in Drupal 10.0 and post it here? 🙏

schoenef’s picture

I think the issue is editor.editor.basic_html, it might be a lost migration or something. In the frontend it shows that now editor is selected, but in the config it has ckeditor5.

I attached a screenshot of the UI under drupal 10.0

Many migrations around the world are probably already in this state, as linkit 6.0 allows to upgrade to 10.0 but no further until it get's updated to 6.1.

Thx for looking into this!
Andreas

wim leers’s picture

Thanks for exporting those 3 filter.format.* config entities 👍

  • full_html looks fine — it contains:
    …
    settings:
      toolbar:
        items:
    …
    
  • webform_default looks fine — same as above
  • basic_html looks wrong — it contains:
    …
    editor: ckeditor5
    settings:
      toolbar:
        rows:
    …

basic_html claims to be using CKEditor 5, but its configuration is still for CKEditor 4.


Unfortunately the config export you shared is only showing the symptom (the resulting bad state), not the root cause (the original state that allowed you to get to this point) — I still need to figure out the steps to reproduce this.

Questions to narrow down the root cause:

  1. It sounds like when you were on Drupal 10.0, you had already upgraded all text formats to CKEditor 5?
  2. How did you perform the CKEditor 4 → 5 upgrade?
  3. Do you have a config/DB back-up of when you were still on CKEditor 4?
  4. The https://www.drupal.org/files/issues/2024-02-05/Screenshot%202024-02-05%2... screenshot does not even show basic_html (nor webform_default actually). That is caused by #2502637: Disabled text formats can't be seen in the GUI.
  5. Do you have any content actually using the basic_html text format? (run the query SELECT COUNT(*) FROM node__body WHERE body_format = 'basic_html' to find out)

Wim Leers credited catch.

wim leers’s picture

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

Version: 10.2.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

shraddhashilimkar’s picture

StatusFileSize
new2.48 KB

in_array(): Argument #2 ($haystack) must be of type array, null given in in_array()
core/modules/ckeditor5/ckeditor5.module(635): in_array('codeBlock', NULL, true)

shraddhashilimkar’s picture

in_array(): Argument #2 ($haystack) must be of type array, null given in in_array()
core/modules/ckeditor5/ckeditor5.module(635): in_array('codeBlock', NULL, true)

smustgrave’s picture

Status: Postponed (maintainer needs more info) » Closed (outdated)
Issue tags: +Bug Smash Initiative

Going to say this is outdated. 10.2, 10.3, etc updates appear to be working fine.

quietone’s picture

Version: 11.x-dev » 10.6.x-dev
Assigned: Unassigned » quietone
Status: Closed (outdated) » Postponed (maintainer needs more info)

As an update issue this needs more consideration before closing since it may be preventing a site from updating.

Assigning to review sometime in the week or so.

quietone’s picture

Title: [10.2] ckeditor5_post_update_code_block() throws an error for format using CKE5 but with CKE4 settings » ckeditor5_post_update_code_block() throws an error for format using CKE5 but with CKE4 settings
Issue summary: View changes
Status: Postponed (maintainer needs more info) » Needs review

I was reminded in #Bugmash about this issue.

The comments by @wim leers, explains what is happening here. I have updated the IS to indicate the work around and that #2628144: Ensure that ConfigImport is taking place against the same code base is the way to prevent this. I will check with the other release managers about this one.

longwave’s picture

Status: Needs review » Reviewed & tested by the community

Looking at the patch this is just a minor hardening for the case where the settings array isn't the expected shape, given this prevents an edge case failure in the upgrade path I think we should just go ahead and commit this.

longwave’s picture

Posted the patch as an MR so the CI can run.

quietone’s picture

Assigned: quietone » Unassigned
xjm’s picture

Priority: Minor » Normal
xjm’s picture

@smustgrave inquired about whether this is still eligible to backport. I didn't review the issue closely, but in general fixes to the upgrade path are the sort of thing we fix in maintenance minors, so we could consider it for backport after beta1 or even in a patch release if it's otherwise non-disruptive.

  • catch committed 6549160d on 10.6.x
    fix: #3419203 ckeditor5_post_update_code_block() throws an error for...
catch’s picture

Status: Reviewed & tested by the community » Fixed

I think this is still OK for a patch release, and last chance to get it in so people can upgrade, and then get past this onto Drupal 11.

Committed/pushed to 10.6.x, thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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