You are here

public function WebformSubmissionDevelGenerateTrait::_validateDrushParams in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/Plugin/DevelGenerate/WebformSubmissionDevelGenerateTrait.php \Drupal\webform\Plugin\DevelGenerate\WebformSubmissionDevelGenerateTrait::_validateDrushParams()
2 calls to WebformSubmissionDevelGenerateTrait::_validateDrushParams()
WebformSubmissionDevelGenerate::validateDrushParams in src/Plugin/DevelGenerate/WebformSubmissionDevelGenerate.php
WebformSubmissionDevelGenerateDeprecated::validateDrushParams in src/Plugin/DevelGenerate/WebformSubmissionDevelGenerateDeprecated.php

File

src/Plugin/DevelGenerate/WebformSubmissionDevelGenerateTrait.php, line 396

Class

WebformSubmissionDevelGenerateTrait
Provides a WebformSubmissionDevelGenerate trait.

Namespace

Drupal\webform\Plugin\DevelGenerate

Code

public function _validateDrushParams($args) {
  $webform_id = array_shift($args);
  $webform_ids = [
    $webform_id => $webform_id,
  ];
  $values = [
    'webform_ids' => $webform_ids,
    'num' => array_shift($args) ?: 50,
    'kill' => empty($args['kill']) ? FALSE : TRUE,
  ];
  if (empty($webform_id)) {
    throw new \Exception(dt('Webform ida required'));
  }
  if (!$this
    ->getWebformStorage()
    ->load($webform_id)) {
    throw new \Exception(dt('Invalid webform name: @name', [
      '@name' => $webform_id,
    ]));
  }
  if ($this
    ->isNumber($values['num']) === FALSE) {
    throw new \Exception(dt('Invalid number of submissions: @num', [
      '@num' => $values['num'],
    ]));
  }
  $entity_type = $args['entity-type'];
  $entity_id = $args['entity-id'];
  if ($entity_type || $entity_id) {
    if ($error = $this
      ->validateEntity($webform_ids, $entity_type, $entity_id)) {
      throw new \Exception($error);
    }
    else {
      $values['entity-type'] = $entity_type;
      $values['entity-id'] = $entity_id;
    }
  }
  return $values;
}