function ContentDevelGenerate::validateDrushParams
Same name in other branches
- 5.x devel_generate/src/Plugin/DevelGenerate/ContentDevelGenerate.php \Drupal\devel_generate\Plugin\DevelGenerate\ContentDevelGenerate::validateDrushParams()
Overrides DevelGenerateBaseInterface::validateDrushParams
File
-
devel_generate/
src/ Plugin/ DevelGenerate/ ContentDevelGenerate.php, line 520
Class
- ContentDevelGenerate
- Provides a ContentDevelGenerate plugin.
Namespace
Drupal\devel_generate\Plugin\DevelGenerateCode
public function validateDrushParams(array $args, array $options = []) {
$add_language = StringUtils::csvToArray($options['languages']);
// Intersect with the enabled languages to make sure the language args
// passed are actually enabled.
$valid_languages = array_keys($this->languageManager
->getLanguages(LanguageInterface::STATE_ALL));
$values['add_language'] = array_intersect($add_language, $valid_languages);
$translate_language = StringUtils::csvToArray($options['translations']);
$values['translate_language'] = array_intersect($translate_language, $valid_languages);
$values['add_type_label'] = $options['add-type-label'];
$values['kill'] = $options['kill'];
$values['feedback'] = $options['feedback'];
$values['title_length'] = 6;
$values['num'] = array_shift($args);
$values['max_comments'] = array_shift($args);
$all_types = array_keys(node_type_get_names());
$default_types = array_intersect([
'page',
'article',
], $all_types);
$selected_types = StringUtils::csvToArray($options['bundles'] ?: $default_types);
if (empty($selected_types)) {
throw new \Exception(dt('No content types available'));
}
$values['node_types'] = array_combine($selected_types, $selected_types);
$node_types = array_filter($values['node_types']);
if (!empty($values['kill']) && empty($node_types)) {
throw new \Exception(dt('To delete content, please provide the content types (--bundles)'));
}
// Checks for any missing content types before generating nodes.
if (array_diff($node_types, $all_types)) {
throw new \Exception(dt('One or more content types have been entered that don\'t exist on this site'));
}
$values['authors'] = is_null($options['authors']) ? [] : explode(',', $options['authors']);
if ($this->isBatch($values['num'], $values['max_comments'])) {
$this->drushBatch = TRUE;
$this->develGenerateContentPreNode($values);
}
return $values;
}