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
The callback
process plugin works with any global callback function: either a global function or a public, static method.
Drupal has a lot of services that are essentially global. It would be convenient to use a method from a service class as a callback.
Proposed resolution
Add a new plugin, extending the callback
plugin. Example usage:
process:
filemime:
plugin: service
service: file.mime_type.guesser
method: guess
source: filename
Remaining tasks
User interface changes
None
API changes
None
Data model changes
None
Issue fork migrate_plus-3218356
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
benjifisherI created a MR to implement the proposed resolution. It is so simple that it feels like cheating.
I am marking this issue NW for some error handling and an automated test.
Comment #3
benjifisherIf we like this approach, then I think we can close #3055302: Process plugin: file_mimetype as a duplicate. I borrowed the usage example from there.
Comment #5
benjifisherThere are now about 4 times as many lines to validate the configuration as there are to do everything else. And the test class is more than twice as long (by line count) as the plugin class.
It all seems kind of silly until I remind myself how annoyed I get when I make a mistake and the error message is not helpful. ;)
Comment #6
MatroskeenAdded some feedback, but overall it looks good to me!
I'm wondering if we need to mention somehow the unpack feature - https://www.drupal.org/node/3205079.
Comment #7
benjifisher@Matroskeen:
Thanks for the review! I made most of the changes you recommended.
That is a little tricky, since that option is only available with Drupal 9.2.0 or later. Along with an
@see
reference to the corecallback
plugin, I addedI think we can leave it at that.
Comment #8
MatroskeenThanks! It looks good to me. I pushed a quick change for the namespace in @see section.
Current test coverage looks good to me, so I'm removing "Needs tests" tag.
I would RTBC, but I didn't test it yet 😉
Comment #9
MatroskeenFinally, I had a chance to test it manually - works like a charm!
I did a quick review again and couldn't find anything to complain.
Therefore, this is RTBC for me.
P.S. I was using the example from IS:
If you're trying on Drupal 9.1.0, consider using
guessMimeType
method. See: https://www.drupal.org/node/3126004Comment #10
MatroskeenChecked again - still looks good.
When we do this, we can deprecate the existing Transliterate plugin. Here is a follow-up issue: #3232488: Deprecate Transliteration process plugin.
Comment #13
heddnThanks for your contributions.
Comment #14
heddn