Closed (fixed)
Project:
Drupal core
Version:
8.1.x-dev
Component:
ckeditor.module
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
6 Jan 2016 at 10:57 UTC
Updated:
10 Mar 2016 at 10:04 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
wim leersComment #3
wim leersComment #4
wim leersComment #5
thpoul commentedLet's try and move this forward. Here is a first shot.
Comment #6
wim leersComment #7
wim leersToo long (should fit on one line). What about:
s/to iframe/in iframe/
s/the need to/needing to/
s/in order to do so//
Can you also update those 4 interfaces to get an
@seeto this new interface?s/array/string[]/
This is not yet specific enough; this is going to get the CSS for all CKEditor plugins, whereas we just want it for the enabled CKEditor plugins.
ApparentlyCKEditorPluginManagerdoes not yet have a specific method to get the enabled plugins.So you'll want to factor out aprotected getEnabledPlugins()method out of the already existinggetEnabledPluginFiles()method.Then bothgetEnabledPluginFiles()andgetCssFiles()will be able to call that new protected method.Apparently we should use
$enabled_plugins = array_keys($this->ckeditorPluginManager->getEnabledPluginFiles($editor, TRUE));for that :) And in fact, you already do exactly that inCKEditor::buildContentCssJSSettings().I think we want *this* method to return only CSS files for enabled plugins, then
CKEditor::buildContentCssJSSettings()also becomes much simpler.Or what reason do you see to return all CSS files?
This CSS file is not specific to the
DrupalImageCaptionplugin. It actually is necessary even when this plugin is not enabled, because you can also add captions to tags other than<img>. So, this should go away here and be added back tockeditor_ckeditor_css_alter().The CSS file added here is actually completely specific to
drupalimagecaption. So, it can be loaded unconditionally (you can remove the if-statement).Precisely because thanks to this new interface, this is only going to be invoked if this plugin is active in the first place!
Comment #8
thpoul commentedThank you for the review Wim. Here is the updated version after your suggestions.
I haven't done anything yet with:
I think we want *this* method to return only CSS files for enabled plugins, then CKEditor::buildContentCssJSSettings() also becomes much simpler.Comment #9
thpoul commentedComment #10
wim leersLooking much better already!
s/the//
s/in order to do so//
This comment can be removed altogether.
s/array()/[]/
4 spaces of indentation instead of 2.
Comment #11
thpoul commentedChanges made :) Still needs tests though. Tagging accordingly.
Comment #12
wim leersThis will also need a change record and documentation updates. (The documentation that should be updated lives at https://www.drupal.org/developing/api/8/ckeditor.)
Comment #13
wim leersThank you so much for pushing this forward!
Comment #15
wim leersHm, I wonder why testbot didn't mark this "needs work" given #11 failed.
Comment #16
thpoul commentedAdded a test for the new api addition. Also cleaned up some things and refactored a bit.
Comment #17
thpoul commentedMinor comment fix.
Comment #18
wim leersMostly there :)
Needs to be updated.
Perhaps also add:
This function interface method name is consistent with the base interface's method name:
\Drupal\ckeditor\CKEditorPluginInterface::getFile()and has similar reasoning/requirements ("files, not asset libraries, because this is for CKEditor, not Drupal").So, +1 for the method name.
Retrieves enabled plugins' iframe instance CSS files, keyed by plugin ID.
s/All available/Enabled plugins'
FQCN
Unused.
Unnecessary whitespace change.
The placement of this call is interesting. It's:
hook_ckeditor_css_alter()invocation, meaning that you cannot use that hook to remove CSS files added by CKEditor plugins.ckeditor_stylesheets: []), which is great, because this means themes' CSS can override default styling.Given that the alter hook is already being invoked before the theme's CSS is added, this is consistent with that. Furthermore, if a certain CKEditor plugin is present and it has associated CSS, there is no valid reason to remove that CSS.
So, +1 for this approach.
This is a test implementation. But… there's no new test coverage actually testing this. So, you'll want to expand test coverage:
\Drupal\ckeditor\Tests\CKEditorPluginManagerTest::testCssFiles(), look at\Drupal\ckeditor\Tests\CKEditorPluginManagerTest::testEnabledPlugins()for inspirationAlso: this CKEditor plugin will never be enabled. It will need to implement either
\Drupal\ckeditor\CKEditorPluginButtonsInterfaceor\Drupal\ckeditor\CKEditorPluginConfigurableInterfaceto be able to become enabled. Read the documentation on\Drupal\ckeditor\CKEditorPluginInterface.Comment #21
thpoul commentedHere is the patch after Wim's review. Hopefully most of the comments should be covered. I am wondering if we should add additional test coverage at
\Drupal\ckeditor\Tests\CKEditorPluginManagerTest::testEnabledPlugins()for Case 3Comment #23
wim leers+1
s/plugins/plugins'/
Looks good.
Nit: needs an empty line in between.
Eh, none of those make any sense! Instead of
Meta*, they should all be\Drupal\ckeditor_test\Plugin\CKEditorPlugin\Llama*! Can't believe this went unnoticed all this time!s/llama_css.css/llama.css/
Comment #24
thpoul commentedPatch changed according to feedback. Additional test coverage added for Case 3 of
\Drupal\ckeditor\Tests\CKEditorPluginManagerTest::testEnabledPlugins(). Also changed a the @see ofCKEditorPluginManager::getButtons()to FQCN to match the annotation ofCKEditorPluginManager::getCssFiles()Comment #26
wim leersInterdiff:
Please bring back the
drupal_get_path()call.Patch:
Needs newline in between.
I think this is ready once the patch is green. Thank you! :) :)
Comment #27
thpoul commentedThank you Wim for all the time you took reviewing this!
I did change also the rest of the test file so it is consistent.
There was a foolish approach in the previous patches at
which I corrected in this one. Hopefully we will have green light now :)
Comment #28
thpoul commentedOops :)
Comment #29
wim leersOh, hah, of course! The old code was merging an array of arrays, not an array of strings! :)
The must be removed. It is untrue because it doesn't make sense: there's no need to key this by plugin ID, because this is already for a specific plugin, hence there is no need for any keying. Look e.g. at
DrupalImageCaptionand note that there's no keying going on.s/array/string[]/
Why the
&$css? AFAICT that should be removed.80 cols.
("CSS file" on the second line can be moved to the end of the first line, etc.)
Nit: let's use
Editor::load()instead.This is now very close!
The updated test coverage for
CKEditorPluginManagerTestonly tests the plugin manager. It's not an integration test. The integration test for loading these CSS files lives at\Drupal\ckeditor\Tests\CKEditorTest::testBuildContentsCssJSSetting(). We should update that test coverage: add theLlamaCssbutton, and verify that the additional expected CSS file is indeed being loaded.Only other thing: a change record.
Then this will be ready! :) Thanks again!
Comment #30
thpoul commentedThank you Wim once again for your review!
Changed also the rest of the two test files so they are consistent. Still we need to remove the deprecated
entity_load('editor'.....all around. But this should be done in an other issue I suppose.Added test coverage also in
\Drupal\ckeditor\Tests\CKEditorTest::testBuildContentsCssJSSetting().Comment #31
thpoul commentedAnd here is the draft of the change record: https://www.drupal.org/node/2660712 (Kudos @timplunkett for helping out!)
Comment #32
thpoul commentedA minor change to match the
\Drupal\ckeditor\CKEditorPluginCssInterface::getCssFiles()annotation.Comment #33
wim leersThe CR looks good. I just made it more generic: https://www.drupal.org/node/2660712/revisions/view/9339100/9340882.
You can omit
$cssentirely. This is not a parameter, it is a return value. Hence it has no name. Look at examples elsewhere :)Now they're no longer keyed by plugin ID? Why not?
(This is the plugin manager, and so anything that this does operates on a set of plugins, so it's useful which information is associated with which plugin.)
In #29.1, I was only referring to a plugin implementing the new interface, not to the plugin manager!
Consequently these test changes will also need to be reverted.
Super nit: let's order these alphabetically.
Hm… I can live with that, but a core committer may shoot this down for that reason. IMO it's fine to just use the proper pattern in new code. (It's not as disconcerting as mixing
array()and[]in one file.)Comment #34
thpoul commentedAfter a week of having the flu and lying in bed all day with fever here I am with my new patch :D
Just to be on the safe side, I followed your advice and only applied the
Editor::load()in the new code :)Comment #35
wim leers:( I know the feeling! Didn't have the flu, but did get various small things over the past 2 weeks. Hope you're all better now!
I just did a round of manual testing:
This is the key change, and the actual concrete example/test case in Drupal core. This CSS still is loaded after applying the patch, hence it's working correctly.
If I remove the
CKEditorPluginCssInterfacefrom the list of implemented interfaces, it disappears.Ergo, it works correctly even after manual testing. The automated test coverage is also solid.
Per #12, I updated the documentation at https://www.drupal.org/developing/api/8/ckeditor: https://www.drupal.org/node/2617470/revisions/view/9118520/9372512. Including an indicator this is an API available in Drupal 8.1 and later.
Thanks, @thpoul, great work! :)
Comment #36
catchCouldn't this use __DIR__?
Have a feeling these have been changed in other patches and will conflict.
Same here with __DIR__.
Comment #37
wim leersFair points. @thpoul, can you address those?
Comment #38
wim leersActually, I don't think #36.1 & .3 make sense (: #2351919: Replace uses of drupal_get_path() with __DIR__ where possible did that for places where we use
drupal_get_path(). But here, it's fine to hardcode the path completely. If we want to use__DIR__instead of hardcoded paths, then let's do that for the entire module in one go. Nowhere else do we do this, and definitely not in this module.So, I think only #36.2 needs to be addressed.
Comment #39
catchThat patch is using drupal_get_path()?
Comment #40
wim leersOh, you're right. I thought I remembered it does not, but you're right. Sorry for the confusion.
Comment #41
thpoul commentedRerolled for 8.1.x.
@catch
__DIR__can't be used here because relative paths are expected and tests fail by using it. For example #2351919-30: Replace uses of drupal_get_path() with __DIR__ where possible had the same issue and finally was decided to stay withdrupal_get_path('module', 'ckeditor').Comment #42
wim leersComment #43
catchCommitted/pushed to 8.1.x, thanks!
Comment #45
wim leersYay!
Congrats @thpoul, this is a significant addition to Drupal 8 core! :)
Comment #46
wim leersPublished the CR.
Comment #47
thpoul commentedEpic win! Wouldn't be able to do it without @Wim Leers guidance :) Thank you!