function MediaDevelGenerate::settingsFormValidate

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

Overrides DevelGenerateBase::settingsFormValidate

File

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

Class

MediaDevelGenerate
Provides a plugin that generates media entities.

Namespace

Drupal\devel_generate\Plugin\DevelGenerate

Code

public function settingsFormValidate(array $form, FormStateInterface $form_state) : void {
    // Remove the media types not selected.
    $media_types = array_filter($form_state->getValue('media_types'));
    if ($media_types === []) {
        $form_state->setErrorByName('media_types', $this->t('Please select at least one media type'));
    }
    // Store the normalized value back, in form state.
    $form_state->setValue('media_types', array_combine($media_types, $media_types));
    $skip_fields = is_null($form_state->getValue('skip_fields')) ? [] : self::csvToArray($form_state->getValue('skip_fields'));
    $base_fields = is_null($form_state->getValue('base_fields')) ? [] : self::csvToArray($form_state->getValue('base_fields'));
    $form_state->setValue('skip_fields', $skip_fields);
    $form_state->setValue('base_fields', $base_fields);
}