Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
There's 3 tests fail using PHP 8.1 - confirm it locally on 8.1.0RC6 too
- Drupal\Tests\ckeditor5\Kernel\CKEditor5PluginManagerTest
- Drupal\Tests\ckeditor5\Kernel\SmartDefaultSettingsTest
- Drupal\Tests\ckeditor5\Kernel\ValidatorsTest
Steps to reproduce
See https://www.drupal.org/pift-ci-job/2235570
Automatic conversion of false to array is deprecated
See https://3v4l.org/ahgI7 for why the deprecation is being triggered.
Proposed resolution
- Stop triggering the deprecation
- Improve the documentation
- Rename the method to reflect what it actually does.
Remaining tasks
Renamed a method that was only added in 9.3.x-alpha to a better name.
User interface changes
API changes
Data model changes
None
Release notes snippet
Comment | File | Size | Author |
---|---|---|---|
#15 | 3249240-3-15.patch | 6.92 KB | alexpott |
#9 | 3249240-9.patch | 588 bytes | andypost |
#2 | 3249240-2.patch | 906 bytes | alexpott |
Comments
Comment #2
alexpottTitling the issue properly. \Drupal\ckeditor5\HTMLRestrictionsUtilities seems a super important class. The docs seem a bit thin as I have no idea if PHP 8.1 is allowing us to find a significant issue or not.
The patch attached fixes the deprecation.
I cannot get \Drupal\Tests\ckeditor5\Kernel\SmartDefaultSettingsTest to pass locally regardless of PHP version because...
The array order is swapped.
Also in
Drupal\Tests\ckeditor5\Kernel\ValidatorsTest
the line$restricted_html_format_filters = Yaml::parseFile('profiles/standard/config/install/filter.format.restricted_html.yml')['filters'];
causes problems for local tests. It assumes that the tests are being run in from /core which is incorrect. If I fix this line to determine the path relative to the test then the tests fails for the same array ordering reasons above.We need to fix this brittle-ness. Will create an issue for making these test able to run locally.
Comment #3
alexpottOpened #3249263: CKEditor 5 needs validate the filters in the correct order - CKEditor 5 tests fail locally. for the local fails.
Comment #4
andypostthere's few people been involved there
https://git.drupalcode.org/project/ckeditor5/-/blame/1.0.x/src/HTMLRestr...
Comment #5
andypostI can't get how FALSE could appear here, looks it needs assert() here to be able to catch which tag's settings caused it
maybe it's related to upgrade path
Comment #6
andypostbtw needs to ping @mixologic to update CI images to latest RC6 as PHP 8.1.0RC5 used in tests
Comment #7
alexpott@andypost this get's set to FALSE in
\Drupal\ckeditor5\HTMLRestrictionsUtilities::allowedElementsStringToHtmlFilterArray()
specifically the line that does:It has nothing to do with upgrade paths.
Comment #8
andypostUsed to debug it and it's clear that
FALSE
means that no attributes allowed for tag also looking at data structures it could be optimized - no reason to use keyed array as values alwaysTRUE
Comment #9
andypostI'm sure it should always set the value as tests expect it so just changed default value
Comment #10
andypostThe class was added in related issue so I asked review #3222852-32: <dl> <dt> <dd> by introducing "Manually editable HTML tags" configuration on Source Editing
Comment #12
alexpottI think I agree that #9 is the correct fix. But then we need to follow on from this and change
\Drupal\ckeditor5\HTMLRestrictionsUtilities::allowedElementsStringToHtmlSupportConfig
fromto
I think we might be able to lose the
assert(is_array($attributes));
because we're going to foreach on it anyway.And \Drupal\ckeditor5\HTMLRestrictionsUtilities::cleanAllowedHtmlArray() can also be cleaned up to be just
Can also remove the
if (is_array($attributes)) {
check in\Drupal\ckeditor5\HTMLRestrictionsUtilities::toReadableElements()
Comment #13
alexpottHmmm.... the problem is the code in
\Drupal\ckeditor5\Plugin\CKEditor5PluginManager::findPluginSupportingElement()
with the change in #9 this is behaving differently as an empty array is considered to be offering less broad supported than an array with some elements. If this was a FALSE then it'd be considered to broader.This is the key part of the code:
I think this has two consequences. The fix in #9 is not correct we need to keep the FALSE value to mean all all attributes. But also it means that the fix in #2 is wrong. We should not go from a FALSE value to an array value because that is making the config less broad.
Comment #14
alexpottAfter running tests and mucking about with ckeditor5 I'm not convinced the solution proposed #13 #13 is correct. Discovered where this ArrayPI comes from - it's all documented in \Drupal\filter\Plugin\FilterInterface::getHTMLRestrictions() - we need to support
'tag' => FALSE
and'tag' => ['class' => TRUE]
The fix in #2 is the correct fix but I think we can improve the documentation here to make it easier to work out in the future.
Comment #15
alexpottPatched attached is the same as #2 with the following additions:
Adds allowed attributes to the elements array.
- I've not changed themI think of this is in-scope because the current docs and method name make it harder to work out what is going on.
Comment #16
Wim LeersI am digging into this too, but as part of reproducing this I ran into significant PHPUnit performance pains, and so I got nerdsniped into fixing those — see #3249443: drupal_phpunit_find_extension_directories() uses infinite recursion ⇒ more directories = slower tests.
Comment #17
alexpottHere's why the deprecation is occurring: https://3v4l.org/ahgI7
Fixing the issue title to reflect the fact that the current behaviour is correct we just don't want it to trigger a deprecation.
Comment #18
Wim LeersI 💯% agree! That's why for a long time I've been advocating for #3228334: Refactor HTMLRestrictionsUtilities to a HtmlRestrictions value object to happen, with thorough unit test coverage and significantly improved docs. In fact, I already made good progress on that issue, but newly CKEditor 5 JS-related data loss criticals forced me to pushing it forward.
(It's not yet been moved into core's
ckeditor5.module
component because I still need to move the MR over.)is wrong. We can't and shouldn't change this. This structure has meaning: it's the same structure as
\Drupal\filter\Plugin\FilterInterface::getHTMLRestrictions()
's return value.You saying that makes me want to point to #3228334: Refactor HTMLRestrictionsUtilities to a HtmlRestrictions value object once more. Reading between the lines, I suspect you agree that issue is critically important?
This is the critical addition to avoid the PHP 8.1-only deprecation error.
Comment #19
larowlanComment #21
larowlanThe change looks good and makes sense to me. Nice work with all the documentation additions @alexpott.
Looking forward to seeing how #3228334: Refactor HTMLRestrictionsUtilities to a HtmlRestrictions value object ends up - plus one for a value object.
Committed 65aaec6 and pushed to 9.4.x.
Backported to 9.3.x