Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • 3
    Be careful using this method because drush is assuming the context is CLI so depending on the command it could not work as expected when is run from UI, but you could use the approach for making drush commands calling another commands or other in other CLI contexts like cron execution. Commented Sep 28, 2020 at 9:51
  • 1
    I edited the snippet so the code won't fail if called from UI. It will be valid only if the implementation is aim to be called from CLI (i.e custom drush commands, cron jobs, etc) Commented Mar 2, 2021 at 11:01
  • I would like to add a note how to get result from command execution. Assume we are running next command: $command = \Drupal::service('migrate_tools.commands'); $result = $command->status('migrate_path_alias', ['field' => 'last_imported']);, then to get some field you need iterator_to_array($result)[0]['last_imported'] Commented Jan 28, 2022 at 18:43
  • you have to set $command->setOutput() and $command->setLogger() Commented Mar 20, 2023 at 20:12