You are here

public function CommandGcuSubscriber::onInteract in Update helper 8

Same name and namespace in other branches
  1. 2.x modules/update_helper_checklist/src/Events/CommandGcuSubscriber.php \Drupal\update_helper_checklist\Events\CommandGcuSubscriber::onInteract()

Handle on interactive mode for getting command options.

Parameters

\Drupal\update_helper\Events\CommandInteractEvent $interact_event: Event.

File

modules/update_helper_checklist/src/Events/CommandGcuSubscriber.php, line 153

Class

CommandGcuSubscriber
Subscriber for "generate:configuration:update" command.

Namespace

Drupal\update_helper_checklist\Events

Code

public function onInteract(CommandInteractEvent $interact_event) {
  $command = $interact_event
    ->getCommand();
  $input = $interact_event
    ->getInput();

  /** @var \Drupal\Console\Core\Style\DrupalStyle $output */
  $output = $interact_event
    ->getOutput();
  $update_version = $input
    ->getOption(static::$updateVersionName);
  $update_description = $input
    ->getOption(static::$updateDescription);
  $success_message = $input
    ->getOption(static::$successMessageName);
  $failure_message = $input
    ->getOption(static::$failureMessageName);

  // Get update version.
  if (!$update_version) {
    $update_versions = $this->updateChecklist
      ->getUpdateVersions($input
      ->getOption('module'));

    // Set internal pointer to end, to get last update version.
    end($update_versions);
    $update_version = $output
      ->ask($command
      ->trans('commands.generate.configuration.update.checklist.questions.update-version'), empty($update_versions) ? '8.x-1.0' : current($update_versions));
    $input
      ->setOption(static::$updateVersionName, $update_version);
  }

  // Get update description for checklist.
  if (!$update_description) {
    $update_description = $output
      ->ask($command
      ->trans('commands.generate.configuration.update.checklist.questions.update-description'), $command
      ->trans('commands.generate.configuration.update.checklist.defaults.update-description'));
    $input
      ->setOption(static::$updateDescription, $update_description);
  }

  // Get success message for checklist.
  if (!$success_message) {
    $success_message = $output
      ->ask($command
      ->trans('commands.generate.configuration.update.checklist.questions.success-message'), $command
      ->trans('commands.generate.configuration.update.checklist.defaults.success-message'));
    $input
      ->setOption(static::$successMessageName, $success_message);
  }

  // Get failure message for checklist.
  if (!$failure_message) {
    $failure_message = $output
      ->ask($command
      ->trans('commands.generate.configuration.update.checklist.questions.failure-message'), $command
      ->trans('commands.generate.configuration.update.checklist.defaults.failure-message'));
    $input
      ->setOption(static::$failureMessageName, $failure_message);
  }
}