You are here

public function YamlFormSubmissionDevelGenerate::validateDrushParams in YAML Form 8

File

src/Plugin/DevelGenerate/YamlFormSubmissionDevelGenerate.php, line 283

Class

YamlFormSubmissionDevelGenerate
Provides a YamlFormSubmissionDevelGenerate plugin.

Namespace

Drupal\yamlform\Plugin\DevelGenerate

Code

public function validateDrushParams($args) {
  $yamlform_id = array_shift($args);
  $yamlform_ids = [
    $yamlform_id => $yamlform_id,
  ];
  $values = [
    'yamlform_ids' => $yamlform_ids,
    'num' => array_shift($args) ?: 50,
    'kill' => drush_get_option('kill') ?: FALSE,
  ];
  if (empty($yamlform_id)) {
    return drush_set_error('DEVEL_GENERATE_INVALID_INPUT', dt('Form id required'));
  }
  if (!$this->yamlformStorage
    ->load($yamlform_id)) {
    return drush_set_error('DEVEL_GENERATE_INVALID_INPUT', dt('Invalid form name: @name', [
      '@name' => $yamlform_id,
    ]));
  }
  if ($this
    ->isNumber($values['num']) == FALSE) {
    return drush_set_error('DEVEL_GENERATE_INVALID_INPUT', dt('Invalid number of submissions: @num', [
      '@num' => $values['num'],
    ]));
  }
  $entity_type = drush_get_option('entity-type');
  $entity_id = drush_get_option('entity-id');
  if ($entity_type || $entity_id) {
    if ($error = $this
      ->validateEntity($yamlform_ids, $entity_type, $entity_id)) {
      return drush_set_error('DEVEL_GENERATE_INVALID_INPUT', $error);
    }
    else {
      $values['entity-type'] = $entity_type;
      $values['entity-id'] = $entity_id;
    }
  }
  return $values;
}