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.
Percursor to #2625696: Make migrations themselves plugins instead of config entities
Problem/Motivation
#2625696: Make migrations themselves plugins instead of config entities wants to move migrations to plugins. In order to do this it wants to have a YAML discovery where a single plugin resides in a file. Other projects with complex plugins have asked for something similar - specifically https://www.drupal.org/project/skinr
Proposed resolution
Add a new YamlDirectoryDiscovery that can scan directories for YAML files and key them by an arbitrary value from the data.
Remaining tasks
User interface changes
None
API changes
New discovery class to support this.
Data model changes
None
Comment | File | Size | Author |
---|---|---|---|
#28 | 2671034-28.patch | 17.01 KB | alexpott |
#28 | 22-28-interdiff.txt | 3.01 KB | alexpott |
#22 | 2671034-22.patch | 16.74 KB | alexpott |
#22 | 20-22-interdiff.txt | 6.63 KB | alexpott |
#20 | 2671034-20.patch | 16.58 KB | alexpott |
Comments
Comment #2
alexpottThe patch attached adds the discovery part of this. Now just need to do the plugin discovery part of this.
Comment #3
dawehnerLet's skip that, its pointless IMHO
Can we add the exception onto the other exception as previous exception?
What about using a iterator?
Let's use
$this->assertCount()
We could put
@covers ::getIdentifier
Comment #4
alexpottThanks for the review @dawehner
Also added proper plugin discovery and tests for it.
Comment #5
dawehner/me waits for damian to appear on this issue.
Comment #6
benjy CreditAttribution: benjy at PreviousNext commentedAll looks pretty good to me, just wondering do we need this cast?
Comment #7
damiankloip CreditAttribution: damiankloip at Tag1 Consulting commentedYes, I spoke to Daniel briefly about suggesting an iterator instead. Looks like you've already done that - nice!
If we're already using the FileSystem iterator, IMO it would be nice to have the logic encapsulated in an iterator of its own. This similar pattern must be used at least a couple of times (maybe more) in core alone? So having one goto way to get and iterate YAML files in a directly would be nice.
Something like this maybe.. Thoughts?
EDIT: Sorry, should have given this file a .txt extension!
Comment #8
damiankloip CreditAttribution: damiankloip at Tag1 Consulting commentedNit: Is this the preferred way to set expected exceptions now? I prefer using the annotation myself. Just seems easier to spot when scanning the test.
Comment #9
alexpott@damiankloip I'm not sure that we need to generalise that here. Maybe we can open a separate issue to look at generalising file iteration. I'm not sure that Discovery is the right place for this.
Comment #10
damiankloip CreditAttribution: damiankloip at Tag1 Consulting commentedSure, follow up is OK. That was not a finished product, just a suggestion.
Comment #11
damiankloip CreditAttribution: damiankloip at Tag1 Consulting commentedCreated #2671708: Add a RegexDirectoryIterator for that.
Comment #12
alexpott@damiankloip so just to make you lol I realised that your iterator was also making sure we are dealing with a file - which seems eminently sensible - so perhaps it is right to add this here.
Comment #13
alexpottSo now this is blocked on #2671708: Add a RegexDirectoryIterator...
Comment #14
dawehnerhttps://thephp.cc/news/2016/02/questioning-phpunit-best-practices
Comment #15
moonray CreditAttribution: moonray at Chapter Three commentedSkinr module would actually need to be able to find .yml files recursively. e.g. /modules/skinr/skins/plugin1/plugin1.yml and /modules/skinr/skins/plugin2/plugin2.yml
Layout module actually goes a step further and allows arbitrary recursion depth. So the following should also be a valid path: /modules/layout/layouts/static/one-col/one-col.yml
Talking with @dawehner it seems we should probably allow specifying the iterator so you could use a recursive iterator or a more basic one.
Comment #16
moonray CreditAttribution: moonray at Chapter Three commentedI'm not sure this is useful for core or other modules, but I need to be able to find out the .yml file's path. The YamlDirectoryDiscovery component doesn't include this with the data returned, only the provider (module or theme name) is returned.
The reason I would need this info is that the .yml plugin includes paths to css and js files, which are relative to the plugin's directory. Requiring paths in the .yml file to be relative to the module's or theme's root (instead of the plugin's root) would quickly become tedious and error prone.
Comment #17
alexpott@moonray - I think you are right- we should add the plugin path to the information returned
Comment #18
alexpottPatch uses #2671708: Add a RegexDirectoryIterator and adds a the discovery location to the plugin array of data. I think this makes sense since even without recursive plugin finding it is possible the ID and the filename don't match up so this will help to work out what is coming from where.
Comment #19
alexpottPatch was missing for some reason...
Comment #20
alexpottAfter discussing with @dawehner in IRC - trying to make @moonray's life a bit easier by making the iterator easily replaceable with one that can be recursive.
Comment #21
dawehnerNitpick: should be typehinted with string
This is a bit confusing. Don't we want to do something like
$data['plugin_definition_file'] = $file or static::DISCOVERY_PATH
?missing docs on parameter $file
Comment #22
alexpottThanks @dawehner I've fixed the missing typehints. The reason for static::DISCOVERY_PATH was to allow things that extend the discovery to use a different key if they choose and also to not have hardcoded strings everywhere. I've made some changes to make it more obvious. We can't use
'plugin_definition_file'
because that is about plugins and discovery is supposed to be decoupled from that.Comment #23
dawehnerThank you alex, this clarifies it.
Comment #24
damiankloip CreditAttribution: damiankloip at Tag1 Consulting commented+1 Just looked through the most recent patch again - looks grrrrreat!
Comment #25
moonray CreditAttribution: moonray at Chapter Three commentedWould it make sense to use 'pathname' like the Extension class to keep things consistent, instead of '_discovered_file_path'? Of course, Extension is an object and only exposes the getPathname() function, not the actual pathname variable. And there is a chance to conflict with a 'pathname' key in the .yml file. But I thought I'd throw this out there.
Comment #26
dawehner@moonray Well the point alex made earlier is: we want to not expose the information by default, at least not super visible. Most plugins should really not care about their location.
Comment #27
catchOverall this looks good but a lot of inconsistencies/typos in the comments.
The suffix for the file cache key.
This is very confusing - could we replace it with something closer to the @param docs?
This doesn't match the property documentation.
This method is exists.
"Allows directories containing YAML files to define plugin definitions."
The directories themselves don't define the plugin definitions.
Comment #28
alexpott@catch thanks for the review.
Patch attached addresses everything - I went in a slightly different direction for point 5.
Comment #29
alexpottGiven the fixes were only docs fixes setting back to rtbc.
Comment #31
catchCommitted/pushed to 8.1.x, thanks!