function ContentDevelGenerate::validateDrushParams
Same name in other branches
- 4.x devel_generate/src/Plugin/DevelGenerate/ContentDevelGenerate.php \Drupal\devel_generate\Plugin\DevelGenerate\ContentDevelGenerate::validateDrushParams()
- 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 375
Class
- ContentDevelGenerate
- Provides a ContentDevelGenerate plugin.
Namespace
Drupal\devel_generate\Plugin\DevelGenerateCode
public function validateDrushParams($args, $options = []) {
$add_language = $this->isDrush8() ? drush_get_option('languages') : $options['languages'];
if (!empty($add_language)) {
$add_language = explode(',', str_replace(' ', '', $add_language));
// Intersect with the enabled languages to make sure the language args
// passed are actually enabled.
$values['values']['add_language'] = array_intersect($add_language, array_keys($this->languageManager
->getLanguages(LanguageInterface::STATE_ALL)));
}
$values['kill'] = $this->isDrush8() ? drush_get_option('kill') : $options['kill'];
$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(array(
'page',
'article',
), $all_types);
if ($this->isDrush8()) {
$selected_types = _convert_csv_to_array(drush_get_option('types', $default_types));
}
else {
$selected_types = StringUtils::csvToArray($options['types'] ?: $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('Please provide content type (--types) in which you want to delete the content.'));
}
// 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'));
}
return $values;
}