You are here

public function WebformScheduledEmailCommands::drush_webform_scheduled_email_cron_validate in Webform 8.5

Same name and namespace in other branches
  1. 6.x modules/webform_scheduled_email/src/Commands/WebformScheduledEmailCommands.php \Drupal\webform_scheduled_email\Commands\WebformScheduledEmailCommands::drush_webform_scheduled_email_cron_validate()

@hook validate webform:scheduled-email:cron

File

modules/webform_scheduled_email/src/Commands/WebformScheduledEmailCommands.php, line 37

Class

WebformScheduledEmailCommands
Webform scheduled email commands for Drush 9.x.

Namespace

Drupal\webform_scheduled_email\Commands

Code

public function drush_webform_scheduled_email_cron_validate(CommandData $commandData) {
  $arguments = $commandData
    ->arguments();
  $webform_id = $arguments['webform_id'];
  $handler_id = $arguments['handler_id'];

  // Get and validate optional $webform_id parameter.
  $webform = NULL;
  if ($webform_id) {
    $webform = Webform::load($webform_id);
    if (!$webform) {
      throw new \Exception(dt('Webform @id not recognized.', [
        '@id' => $webform_id,
      ]));
    }
  }

  // Get and validate optional $handler_id parameter.
  if ($handler_id) {
    try {
      $handler = $webform
        ->getHandler($handler_id);
    } catch (\Exception $exception) {
      throw new \Exception(dt('Handler @id not recognized.', [
        '@id' => $handler_id,
      ]));
    }
    if (!$handler instanceof ScheduleEmailWebformHandler) {
      throw new \Exception(dt('Handler @id is not a scheduled email handler.', [
        '@id' => $handler_id,
      ]));
    }
  }
}