Problem/Motivation
⚠️ Discovered while reviewing #3312442: [PP-1] Make ready for CKEditor 5, which is updating the ckeditor_bidi module to support CKEditor 5 and provide an automatic upgrade path.
There are two places where we do
$end = $can_access_dblog ?
…
in SmartDefaultSettings.
But only the first is preceded by $can_access_dblog = ($this->currentUser->hasPermission('access site reports') && $this->moduleHandler->moduleExists('dblog'));. The second will crash SmartDefaultSettings if the first case wasn't also hit.
This went unnoticed until now because the first case happens in this if-test:
if (!empty($plugins_enabled) || !$source_editing_additions->allowsNothing()) {
and the second happens in this if-test:
// Generate warning for:
// - The addition of <p>/<br> due to them being fundamental tags.
// - The addition of other tags/attributes previously unsupported by the
// format.
if (!$missing_fundamental_tags->allowsNothing() || !empty($attributes_to_tag) || !empty($added_tags)) {
In Drupal core, the second never happens without the first also happening, because we worked hard to never run into the case of additional attributes or tags being enabled on the text format: if that were to happen, it'd mean that we wouldn't be able to granularly match the HTML enabled for CKEditor 4 plugins!
But … contrib can be different of course: it's possible that it will be less granular in its upgrade path (and hence require supporting additional tags, attributes or attribute values).
Furthermore, it's possible Drupal 9 sites using CKEditor 4 are misconfigured: if the allowed_html is not in sync with the functionality allowed by CKEditor 4, it's possible they did not notice, the upgrade to CKEditor 5 would then automatically fix things for them. Which would then also trigger this warning:
Warning: Undefined variable $can_access_dblog in Drupal\ckeditor5\SmartDefaultSettings->computeSmartDefaultSettings() (line 375 of core/modules/ckeditor5/src/SmartDefaultSettings.php)
Steps to reproduce
See test.
This bug was introduced in #3245967: Messages upon switching to CKEditor 5 are overwhelming.
Proposed resolution
Fix.
Remaining tasks
Review.
User interface changes
None.
API changes
None.
Data model changes
None.
Release notes snippet
N/A
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | 3314511-10.patch | 3.14 KB | wim leers |
| #10 | interdiff-4-10.txt | 628 bytes | wim leers |
| #7 | 3314511-7.patch | 550 bytes | wim leers |
| #7 | interdiff.txt | 628 bytes | wim leers |
| #4 | 3314511-4.patch | 3.93 KB | wim leers |
Comments
Comment #2
wim leersComment #3
wim leersD'oh,
phpcsmistake…Comment #4
wim leersFix.
Comment #6
wim leersBumping priority since literally the next CKE 4 → 5 issue I touched ran into this issue too: #3239667-43: Drupal 10 & CKEditor 5 readiness.
Comment #7
wim leersLet's run the full core test suite again, now that #3 proved the problem and #4 proved it's easily fixed.
Comment #8
wim leers(Not yet queuing a
9.4.xtest of #7, that will need a separate patch per the failure in #4. Let's get this first committed to all other branches.)Comment #9
smustgrave commentedAppears as though the change in #7 already exists on teh 10.1.x branch. So should #4 be tested?
Comment #10
wim leersD'oh. I messed up #7.
Comment #12
wim leersRandom fail.
Comment #13
wim leersHappened again, for another contrib module: #3232190-81: CKEditor 5 readiness.
Comment #15
wim leersComment #16
smustgrave commentedWith this patch on 9.5 I am able to pass all ckeditor_bidi tests.
Rerunning 10.1.x but willing to mark RTBC for now.
Comment #17
alexpottHopefully eventually PHPStan will be used to detect all of this type of thing.
Committed and pushed 1de949a521 to 10.1.x and 540bf4eaac to 10.0.x and e1621872eb to 9.5.x and 151b5e459c to 9.4.x. Thanks!
There's no performance reason to not define this outside the ifs. Fixed this on commit.