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
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | core_cke5_update_fix_10.2_3419203.patch | 2.48 KB | shraddhashilimkar |
| #5 | Screenshot 2024-02-05 at 15.33.31.png | 103.26 KB | schoenef |
| #5 | editor.editor.basic_html.yml | 1003 bytes | schoenef |
| #5 | editor.editor.full_html.yml | 2.1 KB | schoenef |
| #5 | editor.editor.webform_default.yml | 806 bytes | schoenef |
Issue fork drupal-3419203
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:
- 3419203-ckeditor5postupdatecodeblock-throws-an
changes, plain diff MR !13492
Comments
Comment #2
schoenef commentedThis patch worked for me:
Comment #3
schoenef commentedOk, the above patch is for Drpal 10.1, for 10.2 this one should do:
Comment #4
wim leersActually,
can never be NULL 😅
Can you please export your config as it was in Drupal 10.0 and post it here? 🙏
Comment #5
schoenef commentedI 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
Comment #6
wim leersThanks for exporting those 3
filter.format.*config entities 👍full_htmllooks fine — it contains:webform_defaultlooks fine — same as abovebasic_htmllooks wrong — it contains:basic_htmlclaims 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:
basic_html(norwebform_defaultactually). That is caused by #2502637: Disabled text formats can't be seen in the GUI.basic_htmltext format? (run the querySELECT COUNT(*) FROM node__body WHERE body_format = 'basic_html'to find out)Comment #8
wim leersBy the way, the only hunch I have right now is that this has the same root cause as the one @catch surfaced at #3374544-10: TypeError: array_intersect(): Argument #1 ($array) must be of type array, string given in array_intersect() (line 203 of .../core/modules/ckeditor5/src/Plugin/CKEditor5PluginManager.php)., which would've been prevented by #2628144: Ensure that ConfigImport is taking place against the same code base.
Comment #9
wim leersComment #11
shraddhashilimkar commentedin_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)
Comment #12
shraddhashilimkar commentedin_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)
Comment #13
smustgrave commentedGoing to say this is outdated. 10.2, 10.3, etc updates appear to be working fine.
Comment #14
quietone commentedAs 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.
Comment #15
quietone commentedI 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.
Comment #16
longwaveLooking 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.
Comment #18
longwavePosted the patch as an MR so the CI can run.
Comment #19
quietone commentedComment #20
xjmComment #21
xjm@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.
Comment #24
catchI 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!