The Drush and Drupal Console teams are investigating a better way to find contrib module command files using tagged services in a modules services.yml file. Currently, this can be done by creating a subclass of DrupalKernel inside of Drush or DrupalConsole. The Drush PR to do this is here: https://github.com/drush-ops/drush/pull/2169
We are presently planning on moving ahead with this strategy, although there is some fragility in that the technique could break if createFromRequest() changed in some future release. If we had a public function in core that allowed us to add the ServiceModifierInterface to the container builder, then we would have future-proof access to the tagged services. The Drush PR already tests for the existence of the DrupalKernel::addServiceModifier() method. If found, the core DrupalKernel is used; if it is not found, then Drush uses its own subclass of DrupalKernel that provides this function.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | 2718933-4.patch | 947 bytes | tstoeckler |
| #2 | 2718933-2.patch | 2.03 KB | greg.1.anderson |
Comments
Comment #2
greg.1.anderson commentedPatch to provide this functionality.
Comment #3
greg.1.anderson commentedForgot to set status.
Comment #4
tstoecklerYou can already add service providers by modifying
$GLOBALS['conf']['container_service_providers']which Drush could do before bootstrapping the Drupal kernel. However, we currently do not in fact check forServiceModifierInterface, onlyServiceProviderInterface. So I'm wondering if something like the attached patch would be sufficient instead?Comment #6
tstoecklerHa, I totally forgot about
ModifyServiceDefinitionsPass. So #4 is bogus. That leaves the question whether Drush can actually achieve registering a service modifier by simply manipulating$GLOBALS['conf']['container_service_providers']?Comment #7
greg.1.anderson commentedSo, we have this:
There is no facility to run a service modifier; only service providers are run here.
It is in fact possible for us to do our work in
ServiceProviderInterface::register()instead ofServiceModifierInterface::alter(), though, since the functions behave identically, despite having different names and different purposes. I modified the fallback code to do this, and it does in fact work. This is more stable than the fallback we were using (the DrupalKernel subclass), but it is a little bit of a hack since it depends on $GLOBALS and is using the wrong interface name. I guess this is what #4 was trying to rectify, except that the service provider $GLOBALS uses ServiceModifierInterface for a different purpose, and the service modifiers added there cannot run here. That begs the question whether there should, perhaps, be a THIRD interface, e.g. CompilerPassProviderInterface, to use in this location without conflating classes that want to add compiler passes with classes that want to register services or alter services.I prefer #2, but could abandon this patch and just use the workaround if the general consensus is that it's not worth pursuing this change. Perhaps it is too pedantic to object to using an interface simply because it has the wrong name; however, the wrong name also implies the wrong contract. Adding service providers pretty much has to happen in the same time and place as the addition of compiler passes, so there is probably little risk to this use.
I guess I can't set the status back to 'needs review'; the testbot would just run #4 and put it back to 'needs work' again.
Comment #8
dawehnerConceptually an alter pass on that point just makes sense, given there you want to potentially change some of the definitions on a per environment level.
Comment #23
smustgrave commentedThank you for sharing your idea for improving Drupal.
We are working to decide if this proposal meets the Criteria for evaluating proposed changes. There hasn't been any discussion here for over 8 years which suggests that this has either been implemented or there is no community support. Your thoughts on this will allow a decision to be made.
Since we need more information to move forward with this issue, the status is now Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.
Thanks!
Comment #24
smustgrave commentedWanted to bump 1 more time if a desired feature still?