You are here

public function MediaDevelGenerate::settingsFormValidate in Devel 4.x

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

Form validation handler.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides DevelGenerateBase::settingsFormValidate

File

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

Class

MediaDevelGenerate
Provides a plugin that generates media entities.

Namespace

Drupal\devel_generate\Plugin\DevelGenerate

Code

public function settingsFormValidate(array $form, FormStateInterface $form_state) {

  // 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));
}