You are here

public static function MediaEditForm::saveMedia in Media Directories 8

Same name and namespace in other branches
  1. 3.x modules/media_directories_ui/src/Form/MediaEditForm.php \Drupal\media_directories_ui\Form\MediaEditForm::saveMedia()
  2. 2.x modules/media_directories_ui/src/Form/MediaEditForm.php \Drupal\media_directories_ui\Form\MediaEditForm::saveMedia()

Form submission 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.

Return value

\Drupal\Core\Ajax\AjaxResponse An AJAX response.

File

modules/media_directories_ui/src/Form/MediaEditForm.php, line 206

Class

MediaEditForm
Class MediaEditForm.

Namespace

Drupal\media_directories_ui\Form

Code

public static function saveMedia(array &$form, FormStateInterface $form_state) {
  $response = new AjaxResponse();
  $added_media = $form_state
    ->get('media');
  foreach ($added_media as $delta => $media) {
    EntityFormDisplay::collectRenderDisplay($media, 'media_library')
      ->extractFormValues($media, $form['media'][$delta]['fields'], $form_state);

    // $this->prepareMediaEntityForSave($media);
    $media
      ->save();
  }
  $response
    ->addCommand(new LoadDirectoryContent());
  $response
    ->addCommand(new CloseModalDialogCommand());
  return $response;
}