How to run Drush 10 custom command in Drupal 8 form submit?
Asked Answered
G

0

6

I have created a custom command for drush 10 in my drupal 8 setup. The command works fine from the terminal. However I want to run that command when the user clicks on form submit. I have tried using the below and I am getting the following errors

1. drush_invoke_process("@self", "my-custom-command");

Error: Call to undefined function drush_invoke_process()

2.

$alias_manager = Drush::service('site.alias.manager');
Drush::drush($alias_manager->getSelf(), 'my-custom-command')->run();

Error: Drush::$container is not initialized yet. \Drush::setContainer() must be called with a real container.

Am i missing something? Are there any alternatives to execute a drush command programmatically?

Gene answered 17/5, 2021 at 8:36 Comment(2)
Can you add detailed version of Drupal and Drush you are using?Converter
@KienNguyen Drupal version : 8.9.11 and Drush Commandline Tool 10.3.6Gene

© 2022 - 2024 — McMap. All rights reserved.