Problem/Motivation
@Wim Leers introduced \Drupal\ckeditor5\AdminUi::getSubmittedEditorAndFilterFormat
in #3200008: Validation and editor settings. Ever since then, it's grown into a complex beast.
That, plus other unholy things:
_ckeditor5_editor_form_filter_admin_format_validate()
clears form errors in some scenarios- using
$form_state->getUserInput()
instead of$form_state->getValues()
in many places - duplicate processing of form values — both within the same request, but also in different pieces of code
- …
These are SEVERE risks for the CKEditor 5 module and Drupal core.
Thanks to refactoring and architectural improvements over the past two months, we can get rid of this, we can drastically simplify this. In particular thanks to #3228477: CKEditor5PluginConfigurableInterface should extend PluginFormInterface and ConfigurableInterface instead of adding ::settingsForm(), this is ready for significant simplification and refactoring.
Steps to reproduce
Proposed resolution
- Try to get rid of the
AdminUi
class altogether. - Simplify!!!
Remaining tasks
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#13 | 3218985-13.patch | 2.05 KB | Wim Leers |
#7 | 3218985-reproduce-bug.txt | 769 bytes | Wim Leers |
Issue fork ckeditor5-3218985
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
Comment #2
bnjmnmComment #3
bnjmnmComment #4
Wim LeersI was testing this with:
Comment #5
Wim LeersI think #3219076: When switching from CKEditor 4 to 5, the allowed HTML tags are not yet immediately auto-computed could help simplify this, especially if we make that update
$form_state->get('editor')
🤓Comment #6
Wim Leers#3219076: When switching from CKEditor 4 to 5, the allowed HTML tags are not yet immediately auto-computed was clearly misguided, sorry for the noise.
I was tryint to get to the point where we only run this validation logic if and only if the resulting selected text editor plugin is CKEditor 5, at which point all of this can indeed just be removed.
Comment #7
Wim LeersI can confirm this is still a problem after #3201637: Figure out how to prevent data loss during upgrade/migration path. Patch attached to make testing this simpler.
Comment #8
Wim LeersI think this is the consensus.
Comment #9
Wim LeersActually, I'm struggling to reproduce this now? 😅
Comment #10
Wim LeersSeems like this is a related
@todo
:Comment #11
bnjmnmI'm not surprised this is no longer reproducible as we've made significant changes to the validation process, but it would be good to have a conclusive explanation. Here's something to start with, at least:
In #3201637: Figure out how to prevent data loss during upgrade/migration path, the types of validation checks specifically mentioned in the issue summary were moved to validation constraints. These constraints are checked in two places:
ckeditor.module
When switching to CKEditor 5 from a different (or null) editor. The validators won't fire when switching from CKEditor 5 to a different option.\Drupal\ckeditor5\Plugin\Editor\CKEditor5::validateConfigurationForm
, so it would only be called when the CKEditor 5 config form is builtIn other words, these validators are not really part of the text format form anymore aside from the specific use case of switching to.
I'll dig further as I'd like the evidence to be definitive before closing, but this covers a good chunk I believe.
Comment #12
Wim LeersGreat, thanks for digging deeper! Marking "needs work" since it's not fully done yet, but well on its way obviously :)
Comment #13
Wim LeersIn digging into this, I actually think that we might be able to get rid of most AJAX complexity? 🤞
Comment #16
Wim LeersAlright, going from
ccc6fb3b0e0c35338d1190dbb63875461e289ecc
yesterday to496045c0ad088cbfe7b55577686a5c0b2c662aff
today, I at least gotDrupal\Tests\ckeditor5\FunctionalJavascript\CKEditor5AllowedTagsTest
fromto
That's progress.
I still have no idea how
c654ec7576cc3ccf7a2db8b74c208474c6a08a3b
managed to increase the number of failures though, because nothing is calling it… :OComment #17
Wim LeersFrom
496045c0ad088cbfe7b55577686a5c0b2c662aff
tod62cf32ca703f53d706ce1fa3fd1752ee927fad3
makesCKEditor5Test
go fromto
but made
CKEditor5AllowedTagsTest
go fromto
Argh! Making
CKEditor5Test::testHeadingsPlugin()
pass madeCKEditor5AllowedTagsTest::testAllowedTags()
fail. At least that's a useful hint!Comment #18
Wim LeersPaired with @lauriii. He cannot reproduce the failures locally! He also tested with PHP 8.0, but with SQLite instead of MySQL (should not make a difference) and a newer version of Chrome+chromedriver.
I just pushed a commit which adds strict config schema checking only when PHP assertions are enabled; that should help narrow it down. And that is also a net improvement to DX for CKEditor 5 contrib developers.
Comment #19
Wim LeersLooks like that is triggering net new failures! That's great! Even if this does not get us to green, it helps tracking things down then 👍
But … I just realized that the PHP log entries that commit will generate will not show up, because this branch was started before #3228355: PHP warning when saving text format with CKE5: $form_state->getTriggeringElement() unexpectedly returning NULL — we need to merge in all
1.0.x
changes before it'll start generating useful output. So … doing that next. 🤞Comment #20
Wim LeersI'm now 90% certain that this is indeed caused by strict config schema checking only running on DrupalCI somehow. In the past few commits, I added it explicitly to
\Drupal\ckeditor5\Plugin\Editor\CKEditor5::validateConfigurationForm()
and despite DrupalCI still only showing… I can see that the exact same steps to reproduce are now locally resulting in AJAX responses like
(Fixed that one in
9e56f6712b2aeceb9e9928547c6b2eaae3ca5fb3
.)What's weird is that
\Drupal\Tests\ckeditor5\FunctionalJavascript\CKEditor5TestBase::tearDown()
which was added in #3228355: PHP warning when saving text format with CKE5: $form_state->getTriggeringElement() unexpectedly returning NULL should be causing this to be visible, but it's … just not. It seems that thetearDown()
is perhaps not being called in the case of Functional JS tests failing early? Yet::tearDown()
is supposed to be called always… I could decorate$assert_session->assertWaitOnAjaxRequest();
in CKE5 tests just so we get better error response checking… using the same technique as I added in\Drupal\Tests\media\FunctionalJavascript\CKEditorIntegrationTest::getLastPreviewRequestTransferSize()
.Comment #21
Wim LeersActually … I think I figured out why:
This is because
\Drupal\FunctionalJavascriptTests\JSWebAssert::assertWaitOnAjaxRequest()
triggers a\RuntimeException
that the test runner won't handle. So it instantly aborts the test, without running::tearDown()
!Related core issue: #3061852: [META] Deprecate assertWaitOnAjaxRequest() and make the JsWebAssert::waitFor*() methods behave like real assertions. It's been that way since it was introduced in #2648956: Editing a view leaves old keys hanging, results in invalid schema.
Comment #22
Wim LeersDiscovered a core bug while debugging those last few failures: #3230829: editor_form_filter_format_form_alter() does not remove "editor_plugin" from form state when needed.
Comment #23
Wim LeersAnd @tim.plunkett opened an issue for #21: #3230726: JsWebAssert::assertWaitOnAjaxRequest() should use Behat\Mink\Exception\ExpectationException not RuntimeException!
Comment #24
Wim LeersThe last remaining call to
AdminUi::getSubmittedEditorAndFilterFormat()
was happening inAdminUi::validateConditions()
. In trying to figure out how to get rid of that, I noticed … that it never worked. It was lacking test coverage too. So … refactoring it into validation constraints over at #3231220: Follow-up for #3216244: AdminUi::validateConditions() does not work, convert to validation constraint.That's another good catch prior to opening the core merge request! 🤞
Comment #25
Wim LeersRetitling because this issue was rescoped.
Comment #26
Wim Leers#3218985: CKEditor 5 admin UI's AJAX logic and form alterations are too complex and brittle landed, merged in that commit…
Comment #27
Wim LeersComment #28
tim.plunkettReviewing
Comment #30
tim.plunkettThis is still a very tricky bit of code, but it is much easier to follow the flow now, has helpful assert() calls, and it is well documented. Farewell AdminUi!
Merged!