- Issue created by @wim leers
- Status changed to Needs work
about 1 year ago 1:59pm 3 November 2023 - ๐ฆ๐บAustralia larowlan ๐ฆ๐บ๐.au GMT+10
Should we do these here too?
\Drupal\ckeditor5\Annotation\CKEditor4To5Upgrade
,\Drupal\ckeditor5\Annotation\CKEditor5AspectsOfCKEditor5Plugin
, and\Drupal\ckeditor5\Annotation\DrupalAspectsOfCKEditor5Plugin
If not, we'll need new issues under the meta for them too.
- ๐ง๐ชBelgium wim leers Ghent ๐ง๐ช๐ช๐บ
Yes, let's ๐ I just didn't get to that yet.
- First commit to issue fork.
- Status changed to Needs review
9 months ago 12:12am 28 March 2024 - ๐ณ๐ฟNew Zealand quietone
The 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.
- Status changed to Needs work
9 months ago 3:17pm 28 March 2024 - ๐บ๐ธUnited States smustgrave
Tests appear green. Just moving to NW for tests
- Status changed to Needs review
9 months ago 10:21pm 28 March 2024 - ๐ณ๐ฟNew Zealand quietone
I 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.
- ๐บ๐ธUnited States smustgrave
@Wim leers you tagged for tests in #3 good to remove that tag?
- Status changed to Needs work
8 months ago 6:19pm 13 April 2024 - ๐บ๐ธUnited States smustgrave
Removing 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
- ๐ฎ๐ณIndia keshav patel
Keshav Patel โ made their first commit to this issueโs fork.
- Status changed to Needs review
8 months ago 7:55pm 13 April 2024 - Status changed to RTBC
8 months ago 8:59pm 13 April 2024 - Status changed to Needs work
8 months ago 10:07am 14 April 2024 - ๐ฌ๐งUnited Kingdom alexpott ๐ช๐บ๐
We need to update @CKEditor5AspectsOfCKEditor5Plugin annotations to attributes - and the docs. Same with @DrupalAspectsOfCKEditor5Plugin... also @CKEditor5Plugin
- ๐ฎ๐ณIndia pradhumanjainOSL
pradhumanjain2311 โ made their first commit to this issueโs fork.
- Status changed to Needs review
8 months ago 8:38am 15 April 2024 - ๐ณ๐ฟNew Zealand quietone
@CKEditor5AspectsOfCKEditor5Plugin and @DrupalAspectsOfCKEditor5Pluginin were already converted but I did find the docs that needed to be updated.
- Status changed to RTBC
8 months ago 1:24pm 15 April 2024 - ๐บ๐ธUnited States smustgrave
Document updates seem fine.
Tests kinda show this but applied locally and made sure ckeditor is still working just fine.
- Status changed to Needs work
8 months ago 9:22pm 15 April 2024 - ๐ฌ๐งUnited Kingdom alexpott ๐ช๐บ๐
We 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
- ๐ฆ๐บAustralia kim.pepper ๐โโ๏ธ๐ฆ๐บSydney, Australia
kim.pepper โ made their first commit to this issueโs fork.
- Status changed to Needs review
8 months ago 5:24am 17 April 2024 - ๐ฆ๐บAustralia kim.pepper ๐โโ๏ธ๐ฆ๐บSydney, Australia
Addressed feedback. Just one open question.
- Status changed to Needs work
8 months ago 6:12am 17 April 2024 - ๐ฆ๐บAustralia kim.pepper ๐โโ๏ธ๐ฆ๐บSydney, Australia
I 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.
- First commit to issue fork.
Swapped 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.
- Status changed to Needs review
8 months ago 6:50pm 20 April 2024 Tests are green again, and added test for attribute-based plugin.
- Status changed to RTBC
8 months ago 6:00pm 28 April 2024 - ๐บ๐ธUnited States smustgrave
Circling 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.
- ๐ฌ๐งUnited Kingdom alexpott ๐ช๐บ๐
Committed and pushed db51845290 to 11.x and b00d317e70 to 10.3.x. Thanks!
-
alexpott โ
committed b00d317e on 10.3.x
Issue #3399036 by godotislate, quietone, Wim Leers, kim.pepper, Keshav...
-
alexpott โ
committed b00d317e on 10.3.x
- Status changed to Fixed
8 months ago 9:12am 29 April 2024 -
alexpott โ
committed db518452 on 11.x
Issue #3399036 by godotislate, quietone, Wim Leers, kim.pepper, Keshav...
-
alexpott โ
committed db518452 on 11.x
- Status changed to Needs work
8 months ago 9:29am 29 April 2024 - ๐ง๐ชBelgium wim leers Ghent ๐ง๐ช๐ช๐บ
How are these changes not DX regressions? ๐ฌ
-
- 'The "ckeditor5_invalid_plugin_foo_bar" CKEditor 5 plugin definition must contain a "ckeditor5.plugins" key.', + \ArgumentCountError::class, + NULL,
-
- 'The "ckeditor5_invalid_plugin_foo_bar" CKEditor 5 plugin definition has a "drupal.label" value that is not a string nor a TranslatableMarkup instance.', + \TypeError::class,
-
Enforcement that `ckeditor5.plugins` is required is taking place in `CkEditor5AspectsIfCkEditor5Plugin` attribute constructor now, instead of in `CKEditor5PluginDefinition::validateCKEditor5Aspects()`, and an `\ArgumentCountError` is thrown.
Similarly, the type check for `drupal.label` is from `DrupalAspectsOfCKEditor5Plugin` attribute constructor typehinting instead of `CKEditor5PluginDefinition::validateDrupalAspects()`, and `\TypeError` is 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.
- Status changed to Fixed
8 months ago 9:52am 29 April 2024 - ๐ฌ๐งUnited Kingdom 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.
- Assigned to wim leers
- Status changed to Needs work
8 months ago 1:47pm 29 April 2024 - ๐ง๐ชBelgium wim leers Ghent ๐ง๐ช๐ช๐บ
Only 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.yml
file like this:ckeditor5_invalid_plugin_foo_bar: ckeditor5: {}
Now results in:
1) Drupal\Tests\ckeditor5\Kernel\CKEditor5PluginManagerTest::testInvalidPluginDefinitions with data set "added ckeditor5" ('ckeditor5_invalid_plugin_foo_...r5: {}', 'ArgumentCountError', null) ArgumentCountError: Too few arguments to function Drupal\ckeditor5\Attribute\CKEditor5AspectsOfCKEditor5Plugin::__construct(), 0 passed in /Users/wim.leers/core/core/modules/ckeditor5/src/Attribute/CKEditor5Plugin.php on line 58 and at least 1 expected /Users/wim.leers/core/core/modules/ckeditor5/src/Attribute/CKEditor5AspectsOfCKEditor5Plugin.php:22
versus previously:
1) Drupal\Tests\ckeditor5\Kernel\CKEditor5PluginManagerTest::testInvalidPluginDefinitions with data set "added ckeditor5" ('ckeditor5_invalid_plugin_foo_...r5: {}', 'The "ckeditor5_invalid_plugin..." key.') Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException: The "ckeditor5_invalid_plugin_foo_bar" CKEditor 5 plugin definition must contain a "ckeditor5.plugins" key. /Users/wim.leers/core/core/modules/ckeditor5/src/Plugin/CKEditor5PluginDefinition.php:90 /Users/wim.leers/core/core/modules/ckeditor5/src/Plugin/CKEditor5PluginManager.php:97 /Users/wim.leers/core/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php:339 /Users/wim.leers/core/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php:213 /Users/wim.leers/core/core/modules/ckeditor5/tests/src/Kernel/CKEditor5PluginManagerTest.php:198 /Users/wim.leers/core/vendor/phpunit/phpunit/src/Framework/TestResult.php:728
and similar for now:
1) Drupal\Tests\ckeditor5\Kernel\CKEditor5PluginManagerTest::testInvalidPluginDefinitions with data set "added drupal.label" ('ckeditor5_invalid_plugin_foo_...el: {}', 'TypeError') TypeError: Drupal\ckeditor5\Attribute\DrupalAspectsOfCKEditor5Plugin::__construct(): Argument #1 ($label) must be of type Drupal\Core\StringTranslation\TranslatableMarkup|string|null, array given, called in /Users/wim.leers/core/core/modules/ckeditor5/src/Attribute/CKEditor5Plugin.php on line 59 โฆ
vs previously:
1) Drupal\Tests\ckeditor5\Kernel\CKEditor5PluginManagerTest::testInvalidPluginDefinitions with data set "added ckeditor5" ('ckeditor5_invalid_plugin_foo_...r5: {}', 'The "ckeditor5_invalid_plugin..." key.') The "ckeditor5_invalid_plugin_foo_bar" CKEditor 5 plugin definition has a "drupal.label" value that is not a string nor a TranslatableMarkup instance. โฆ
In other words:
- before this commit a person trying to get a CKEditor 5 plugin working in Drupal got very precise feedback: the exception was saying which exact CKEditor 5 plugin definition was invalid, and where exactly the invalidity was.
- after this commit, that same person will only get a PHP error that does not tie it back to what the person is doing: no mention of the problematic CKEditor 5 plugin definition. If that person is comfortable with an IDE and CKEditor 5, they will be able to narrow it down. Otherwise, they won't. And it'll result in frustration.
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:
- reducing the type-narrowness of
\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 - moving some of the validation into
\Drupal\ckeditor5\Attribute\CKEditor5Plugin::__construct()
, in theis_array(โฆ) === TRUE
case.
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.
- Issue was unassigned.
- Status changed to Needs review
8 months ago 4:47pm 29 April 2024 - ๐ง๐ชBelgium wim leers Ghent ๐ง๐ช๐ช๐บ
I 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.
- Status changed to RTBC
8 months ago 5:27pm 29 April 2024 LGTM. Changes are well documented with clear comments. Nice work!
- ๐ฌ๐งUnited Kingdom alexpott ๐ช๐บ๐
Committed and pushed d18ca8ba04 to 11.x and 8e3a3f6e57 to 10.3.x. Thanks!
-
alexpott โ
committed 8e3a3f6e on 10.3.x
Issue #3399036 follow-up by Wim Leers, godotislate:...
-
alexpott โ
committed 8e3a3f6e on 10.3.x
- Status changed to Fixed
8 months ago 6:53pm 29 April 2024 -
alexpott โ
committed d18ca8ba on 11.x
Issue #3399036 follow-up by Wim Leers, godotislate:...
-
alexpott โ
committed d18ca8ba on 11.x
- ๐ง๐ชBelgium wim leers Ghent ๐ง๐ช๐ช๐บ
Thank 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 ๐ -
alexpott โ
committed db518452 on 11.0.x
Issue #3399036 by godotislate, quietone, Wim Leers, kim.pepper, Keshav...
-
alexpott โ
committed db518452 on 11.0.x