function MediaDevelGenerate::validateDrushParams

Same name in other branches
  1. 5.x devel_generate/src/Plugin/DevelGenerate/MediaDevelGenerate.php \Drupal\devel_generate\Plugin\DevelGenerate\MediaDevelGenerate::validateDrushParams()

Overrides DevelGenerateBaseInterface::validateDrushParams

File

devel_generate/src/Plugin/DevelGenerate/MediaDevelGenerate.php, line 404

Class

MediaDevelGenerate
Provides a plugin that generates media entities.

Namespace

Drupal\devel_generate\Plugin\DevelGenerate

Code

public function validateDrushParams(array $args, array $options = []) {
    $add_language = $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'] = $options['kill'];
    $values['feedback'] = $options['feedback'];
    $values['name_length'] = 6;
    $values['num'] = array_shift($args);
    $all_media_types = array_values($this->mediaTypeStorage
        ->getQuery()
        ->execute());
    $requested_media_types = StringUtils::csvToArray($options['media-types'] ?: $all_media_types);
    if (empty($requested_media_types)) {
        throw new \Exception(dt('No media types available'));
    }
    // Check for any missing media type.
    if ($invalid_media_types = array_diff($requested_media_types, $all_media_types)) {
        throw new \Exception("Requested media types don't exists: " . implode(', ', $invalid_media_types));
    }
    $values['media_types'] = array_combine($requested_media_types, $requested_media_types);
    if ($this->isBatch($values['num'])) {
        $this->drushBatch = TRUE;
        $this->preGenerate($values);
    }
    return $values;
}