Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when dynamically removing command definition in service provider #5055

Closed
DieterHolvoet opened this issue Jan 31, 2022 · 0 comments · Fixed by #5056
Closed

Error when dynamically removing command definition in service provider #5055

DieterHolvoet opened this issue Jan 31, 2022 · 0 comments · Fixed by #5056

Comments

@DieterHolvoet
Copy link
Contributor

Describe the bug
I have a module having Drush commands that should only be registered if a certain other module is installed. If I try to do this using Drush 11, I get the following error:

In CheckExceptionOnInvalidReferenceBehaviorPass.php line 86:

  The service "drush.command.services" has a dependency on a non-existent service "wmscaffold.commands.wmmodel".

To Reproduce
Add a service provider removing a command definition, eg.

<?php

namespace Drupal\wmscaffold;

use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\DependencyInjection\ServiceModifierInterface;

class WmscaffoldServiceProvider implements ServiceModifierInterface
{
    public function alter(ContainerBuilder $container)
    {
        if (!$container->hasDefinition('plugin.manager.wmmodel.model')) {
            $container->removeDefinition('wmscaffold.commands.wmmodel');
            $container->removeDefinition('wmscaffold.hooks.wmmodel');
        }
    }
}

Expected behavior
Not throw an exception.

Actual behavior
An exception was thrown.

Workaround
/

System Configuration

Q A
Drush version? 11.x
Drupal version? 9.x
PHP version 8.x
OS? Mac

Additional information
/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant