public function TermDevelGenerate::validateDrushParams in Devel 8
Same name and namespace in other branches
- 8.3 devel_generate/src/Plugin/DevelGenerate/TermDevelGenerate.php \Drupal\devel_generate\Plugin\DevelGenerate\TermDevelGenerate::validateDrushParams()
- 8.2 devel_generate/src/Plugin/DevelGenerate/TermDevelGenerate.php \Drupal\devel_generate\Plugin\DevelGenerate\TermDevelGenerate::validateDrushParams()
- 4.x devel_generate/src/Plugin/DevelGenerate/TermDevelGenerate.php \Drupal\devel_generate\Plugin\DevelGenerate\TermDevelGenerate::validateDrushParams()
Responsible for validating Drush params.
@Return an array of values ready to be used for generateElements()
Overrides DevelGenerateBaseInterface::validateDrushParams
File
- devel_generate/
src/ Plugin/ DevelGenerate/ TermDevelGenerate.php, line 227
Class
- TermDevelGenerate
- Provides a TermDevelGenerate plugin.
Namespace
Drupal\devel_generate\Plugin\DevelGenerateCode
public function validateDrushParams($args, $options = []) {
$vocabulary_name = array_shift($args);
$number = array_shift($args);
if ($number === NULL) {
$number = 10;
}
if (!$vocabulary_name) {
throw new \Exception(dt('Please provide a vocabulary machine name.'));
}
if (!$this
->isNumber($number)) {
throw new \Exception(dt('Invalid number of terms: @num', array(
'@num' => $number,
)));
}
// Try to convert machine name to a vocabulary id.
if (!($vocabulary = $this->vocabularyStorage
->load($vocabulary_name))) {
throw new \Exception(dt('Invalid vocabulary name: @name', array(
'@name' => $vocabulary_name,
)));
}
$values = [
'num' => $number,
'kill' => $this
->isDrush8() ? drush_get_option('kill') : $options['kill'],
'title_length' => 12,
'vids' => [
$vocabulary
->id(),
],
];
return $values;
}