function MediaDevelGenerate::validateDrushParams

Same name in other branches
  1. 4.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 377

Class

MediaDevelGenerate
Provides a plugin that generates media entities.

Namespace

Drupal\devel_generate\Plugin\DevelGenerate

Code

public function validateDrushParams(array $args, array $options = []) : array {
    $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);
    $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']);
    $all_media_types = array_values($this->mediaTypeStorage
        ->getQuery()
        ->accessCheck(FALSE)
        ->execute());
    $requested_media_types = self::csvToArray($options['media-types'] ?: $all_media_types);
    if ($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;
}