function BlockContentDevelGenerate::validateDrushParams
Overrides DevelGenerateBaseInterface::validateDrushParams
File
-
devel_generate/
src/ Plugin/ DevelGenerate/ BlockContentDevelGenerate.php, line 186
Class
- BlockContentDevelGenerate
- Provides a BlockContentDevelGenerate plugin.
Namespace
Drupal\devel_generate\Plugin\DevelGenerateCode
public function validateDrushParams(array $args, array $options = []) : array {
$add_language = self::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 = self::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['skip_fields'] = is_null($options['skip-fields']) ? [] : self::csvToArray($options['skip-fields']);
$values['base_fields'] = is_null($options['base-fields']) ? [] : self::csvToArray($options['base-fields']);
$values['title_length'] = 6;
$values['num'] = array_shift($args);
$values['max_comments'] = array_shift($args);
$all_types = array_keys($this->blockContentGetBundles());
$selected_types = self::csvToArray($options['block_types']);
if ($selected_types === []) {
throw new \Exception(dt('No Block content types available'));
}
$values['block_types'] = array_combine($selected_types, $selected_types);
$block_types = array_filter($values['block_types']);
if (!empty($values['kill']) && $block_types === []) {
throw new \Exception(dt('To delete content, please provide the Block content types (--bundles)'));
}
// Checks for any missing block content types before generating blocks.
if (array_diff($block_types, $all_types) !== []) {
throw new \Exception(dt('One or more block content types have been entered that don\'t exist on this site'));
}
if ($this->isBatch($values['num'])) {
$this->drushBatch = TRUE;
}
return $values;
}