Closed (fixed)
Project:
Drupal core
Version:
10.3.x-dev
Component:
ckeditor5.module
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
3 Nov 2023 at 13:42 UTC
Updated:
18 May 2024 at 08:19 UTC
Jump to comment: Most recent
Comments
Comment #3
wim leersComment #4
larowlanShould we do these here too?
\Drupal\ckeditor5\Annotation\CKEditor4To5Upgrade,\Drupal\ckeditor5\Annotation\CKEditor5AspectsOfCKEditor5Plugin, and\Drupal\ckeditor5\Annotation\DrupalAspectsOfCKEditor5PluginIf not, we'll need new issues under the meta for them too.
Comment #5
wim leersYes, let's 👍 I just didn't get to that yet.
Comment #7
quietone commentedThe other two plugins are now converted. And I added something to 'function get' which was not the recommended solution but I wanted something so tests would run.
Comment #8
smustgrave commentedTests appear green. Just moving to NW for tests
Comment #9
quietone commentedI don't recall seeing a requirement for additional tests on any other conversion. So, I am changing the status to get reviews of the work currently done here.
Comment #10
smustgrave commented@Wim leers you tagged for tests in #3 good to remove that tag?
Comment #11
smustgrave commentedRemoving the tests tag as we haven't added them to other attribute tickets.
But comment about the typo seems correct as other files have the capital K
Comment #13
keshav patel commentedFixed the typo, please review.
Comment #14
smustgrave commentedBelieve this one is good now.
Comment #15
alexpottWe need to update @CKEditor5AspectsOfCKEditor5Plugin annotations to attributes - and the docs. Same with @DrupalAspectsOfCKEditor5Plugin... also @CKEditor5Plugin
Comment #17
quietone commented@CKEditor5AspectsOfCKEditor5Plugin and @DrupalAspectsOfCKEditor5Pluginin were already converted but I did find the docs that needed to be updated.
Comment #18
smustgrave commentedDocument updates seem fine.
Tests kinda show this but applied locally and made sure ckeditor is still working just fine.
Comment #19
alexpottWe need to replace the plugins with attributes in
grep -R "@CKEditor5Plugin" ./core
./core/modules/ckeditor5/tests/src/Kernel/CKEditor5PluginManagerTest.php: * @CKEditor5Plugin(
./core/modules/ckeditor5/ckeditor5.api.php: * * @CKEditor5Plugin(
grep -R "@DrupalAspectsOfCKEditor5Plugin" ./core
./core/modules/ckeditor5/tests/src/Kernel/CKEditor5PluginManagerTest.php: * drupal = @DrupalAspectsOfCKEditor5Plugin(
./core/modules/ckeditor5/ckeditor5.api.php: * * drupal = @DrupalAspectsOfCKEditor5Plugin(
grep -R "@CKEditor5AspectsOfCKEditor5Plugin" ./core 2111ms Mon 15 Apr 22:19:45 2024
./core/modules/ckeditor5/tests/src/Kernel/CKEditor5PluginManagerTest.php: * ckeditor5 = @CKEditor5AspectsOfCKEditor5Plugin(
./core/modules/ckeditor5/ckeditor5.api.php: * * ckeditor5 = @CKEditor5AspectsOfCKEditor5Plugin(
Also for some unkown reason CKEditor5AspectsOfCKEditor5Plugin was renamed CKEditor5AspectsIfCKEditor5Plugin which is incorrect
Comment #21
kim.pepperAddressed feedback. Just one open question.
Comment #22
kim.pepperI tried to convert the test but ended up in a whole lot of pain. I'm not entirely sure if the sub-attributes make things better or worse.
Comment #24
godotislateSwapped out AnnotationDiscovery for AttributeDiscoveryWithAnnotations and AnnotationBridgeDecorator for AttributeBridgeDecorator. With these changes, tests in Drupal\Tests\ckeditor5\Kernel\CKEditor5PluginManagerTest are failing. Some of that is due to the new CKEditor5AspectsOfCKEditor5Plugin and DrupalAspectsOfCKEditor5Plugin taking named parameters in their constructors vs a values array in their respective annotation classes. The validation tests in CKEditor5PluginManagerTest are failing because there are intentionally arguments missing from the constructors, but it is generating a different kind of exception.
Also, CKEditor5PluginManagerTest needs a sample plugin class using attributes.
Comment #25
godotislateTests are green again, and added test for attribute-based plugin.
Comment #26
smustgrave commentedCircling back to this as a D11 blocker.
From what I can tell the feedback has been addressed.
Applied locally, wasn't entirely sure but test functionality of ckeditor5 and nothing broke.
Unless I'm mistaken believe this is good.
Comment #27
alexpottCommitted and pushed db51845290 to 11.x and b00d317e70 to 10.3.x. Thanks!
Comment #30
wim leersHow are these changes not DX regressions? 😬
Comment #31
godotislateEnforcement that
ckeditor5.pluginsis required is taking place inCkEditor5AspectsIfCkEditor5Pluginattribute constructor now, instead of inCKEditor5PluginDefinition::validateCKEditor5Aspects(), and an\ArgumentCountErroris thrown.Similarly, the type check for
drupal.labelis fromDrupalAspectsOfCKEditor5Pluginattribute constructor typehinting instead ofCKEditor5PluginDefinition::validateDrupalAspects(), and\TypeErroris thrown from the constructor param type mismatch.The exception types and messages are different, but the result is the same. Removed the exception match string because the new exception messages include a folder path string that varies depending on where Drupal files live in the file system.
Comment #32
alexpott@Wim Leers what @godotislate is said. PHP's type system will give you a very precise error and now if you use an IDE it'll tell you too.
Comment #33
wim leersOnly if the CKEditor 5 plugin author uses the PHP attributes plugin definition style, they get a good DX (and in that case I'd say: a better DX, if they're using an IDE, like you both are saying! 👏 And I personally love that! 🤩).
But … I disagree it's equally precise, because the 99% case is a CKEditor 5 plugin definition in YAML, where after this change you will need a Xdebug + knowing how to use it to understand the error.
Most CKEditor 5 plugins are not configurable and hence have no need for a PHP class, and would therefore be unlikely to use the PHP attributes plugin definition style.
The new DX for a CKEditor 5 plugin author using a YAML plugin definition
Defining the module's
*.ckeditor5.ymlfile like this:Now results in:
versus previously:
and similar for now:
vs previously:
In other words:
A huge amount of effort went into ensuring non-ambiguous error messages for invalid CKEditor 5 plugin definitions, for the best possible DX.
Conclusion
I see two choices:
\Drupal\ckeditor5\Attribute\CKEditor5AspectsOfCKEditor5Plugin::__construct()and\Drupal\ckeditor5\Attribute\DrupalAspectsOfCKEditor5Plugin::__construct(), but this would have negative DX consequences for the "PHP Attribute in IDE" scenario ⇒ bad for the minority that defines PHP classes for their CKEditor 5 plugins\Drupal\ckeditor5\Attribute\CKEditor5Plugin::__construct(), in theis_array(…) === TRUEcase.I think the latter is preferable: keep the DX improvements this issue brought for a minority without reducing the DX for the majority.
MR inbound.
Comment #35
wim leersI believe I've fully restored the original DX now. But the validation order is slightly different, so the test cases had to change slightly. This is because the use of the strongly typed PHP attributes forces certain validation to happen earlier now.
Comment #36
godotislateLGTM. Changes are well documented with clear comments. Nice work!
Comment #37
alexpottCommitted and pushed d18ca8ba04 to 11.x and 8e3a3f6e57 to 10.3.x. Thanks!
Comment #40
wim leersThank you, both of you! 😊
And again, nice work on the improved DX for the "wrote a PHP class for my CKEditor 5 plugin" case! 👏
P.S.: we would be able to remove the expected class now, because it's now again always
InvalidPluginDefinitionException. Follow-up issue? Do we leave it as-is? I don't feel strongly about that — it was the DX I felt strongly about 😇Comment #41
andypost+1 to follow-up for #40