Problem/Motivation
If you want to add functionality to an existing toolkit (e.g. extend image type support) you have to extend the toolkit and all it's operations (crop, scale, ...). For example, when trying to add WebP support to Drupal Core's GDToolkit (see #2340645: image effect to convert to webp).
Proposed resolution
Support plugin derivatives for image toolkits. A derivative may extend its base and should have the ID like id = "gd:whatever".
Remaining tasks
User interface changes
None.
API changes
Derivative IDs will have the base plugin ID as prefix: id = "gd:whatever:.
Original report by @attiks
If you want to extend an existing toolkit, you are now forced to extend all effects as well, this is - to say the least - cumbersome.
As an example see #2340645: image effect to convert to webp
Beta phase evaluation
Comments
Comment #1
jelle_sComment #2
claudiu.cristeaThis is a big architectural issue of the toolkit system. Don't think that this is the right way
Comment #3
claudiu.cristeaMy approach is to allow declaration of derivative plugins for image toolkits. The effect is the same but it's more elegant. A derivative is declared
id = "gd:whatever". If you want to override operations, just implement new one having the toolkit definition pointing to the derivative id.This issue is blocked by #2359391: The deriver class should receive the decorated plugin discovery. Attached 2 patches: one for this issue and the other combined with #2359391: The deriver class should receive the decorated plugin discovery for testing.
Comment #4
claudiu.cristeaAdditional check added.
Comment #6
claudiu.cristeaIt seems that we don't need a deriver class. Derivatives are discovered exactly as the base toolkits and the whole logic goes into
ImageToolkitOperationManager::getToolkitOperationPluginId()where we need to check also the base plugin for operations. Now the patch is more compact and does not depend on #2359391: The deriver class should receive the decorated plugin discovery anymore. Somehow we are back to @attiks initial solution but instead of having the "base toolkit" key, we are using the derivative like ID prefixing.The interdiff is against the combined patch.
Comment #8
claudiu.cristeaSmall fix: removed unused "use" statement.
Comment #10
claudiu.cristeaChanged the existing change request to reflect this improvement: https://www.drupal.org/node/1993056/revisions/view/7175637/7745505
Comment #11
attiks commentedQuick code review, looks good to me.
Comments have to be removed
Comment #12
claudiu.cristeaThose are not comments. Those are making your life easier in PhpStorm by giving you rich autocomplete features. And are also good for documenting the types of objects that we are using there.
Comment #13
attiks commentedI know, but they are not 'allowed' in core, sad but true.
Comment #14
claudiu.cristeaOk, ok :)
Comment #17
claudiu.cristeaHey @attiks, this is here for a long time waiting a review. Is this still needed? I guess, yes.
PS: Rerolled.
Comment #18
mondrake1. Should check if $base_toolkit_id is available before creating an instance? The base toolkit may have been uninstalled.
2. Why? We are not passing the ImageToolkitManager to ImageToolkitOperation objects.
3. To keep consistency with gd toolkit, I think this should go under file core/modules/system/tests/modules/image_test/src/Plugin/ImageToolkit/Operation/test/Bar.php and class \Drupal\image_test\Plugin\ImageToolkit\Operation\test\Bar. Same for Foo. Not sure about FooDerived though.
Other than that, nice and useful if anyone wants to support additional image file formats without rewriting entire toolkits. Test coverage is good.
Comment #19
claudiu.cristea$base_toolkit_idis passed, a\Drupal\Component\Plugin\Exception\PluginNotFoundExceptionis thrown. An if() {} doesn't help. But I'm happy with the exception because no plugin derivative should exists without its base plugin.Comment #21
mondrake1. This is also not necessary, then.
2. \Drupal\image_test\Plugin\ImageToolkit\Operation\test\Bar
3. Drupal\image_test\Plugin\ImageToolkit\Operation\test;
2. and 3. also in the other files moved
Comment #22
mondrakeAdded beta evaluation.
Comment #23
mondrake.
Comment #24
claudiu.cristeaThank you.
Comment #25
attiks commentedSorry for the late reply, a bit too busy, patch is looking good
Comment #26
mondrakeThanks @claudiu.cristea.
@attiks is happy too, quoting myself from #18
RTBC
Comment #29
mondrake#27 seems a testbot failure.
Comment #30
xjmThis issue does not meet the criteria for allowed changes during the beta phase (see https://www.drupal.org/core/beta-changes).
Since the patch is BC-compatible (API addition with an added service via constructor injection), it can be made once the 8.1.x branch is open for development, so postponing to that branch. Thanks!
Comment #31
attiks commented#30 Not to start an argument, but not adding this, means contrib cannot override only one method, it has to override everything, postponing this will make it very hard for contrib.
Comment #32
claudiu.cristeaIt was RTBC for 1 months :(
Comment #34
mondrake#24 is still green.
Comment #35
alexpottI think we should be able to make the change without changing the protected method signature which is a BC break that should only be done in major releases unless the method is agreed to be internal. Protected methods are not like service construction which we've agreed can change (within reason) in minor releases.
Comment #36
alexpottAccording to @xjm we protected methods are automatically considered internal see https://www.drupal.org/node/2562903. I've debated whether or not we should avoid the signature change but I think in this case it keeps the code more maintainable and sub classing the ImageToolkitOperationManager should be extremely rare.
Comment #37
alexpottCommitted 3ef563d and pushed to 8.1.x. Thanks!
Comment #40
xjm