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.

CommentFileSizeAuthor
#4 2718933-4.patch947 byteststoeckler
#2 2718933-2.patch2.03 KBgreg.1.anderson

Comments

greg.1.anderson created an issue. See original summary.

greg.1.anderson’s picture

StatusFileSize
new2.03 KB

Patch to provide this functionality.

greg.1.anderson’s picture

Status: Active » Needs review

Forgot to set status.

tstoeckler’s picture

StatusFileSize
new947 bytes

You 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 for ServiceModifierInterface, only ServiceProviderInterface. So I'm wondering if something like the attached patch would be sufficient instead?

Status: Needs review » Needs work

The last submitted patch, 4: 2718933-4.patch, failed testing.

tstoeckler’s picture

Ha, 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'] ?

greg.1.anderson’s picture

So, we have this:

    foreach ($this->serviceProviders['site'] as $provider) {
      if ($provider instanceof ServiceProviderInterface) {
        $provider->register($container);
      }
    }

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 of ServiceModifierInterface::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.

dawehner’s picture

Issue tags: +Needs tests

Conceptually 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.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs work » Postponed (maintainer needs more info)
Issue tags: +stale-issue-cleanup

Thank 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!

smustgrave’s picture

Wanted to bump 1 more time if a desired feature still?

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.