prepareMediaEntityForSave example

$form_display->extractFormValues($media$form['media'][$delta]['fields']$form_state);
    $form_display->validateFormValues($media$form['media'][$delta]['fields']$form_state);
  }

  /** * {@inheritdoc} */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    foreach ($this->getAddedMediaItems($form_state) as $delta => $media) {
      EntityFormDisplay::collectRenderDisplay($media, 'media_library')
        ->extractFormValues($media$form['media'][$delta]['fields']$form_state);
      $this->prepareMediaEntityForSave($media);
      $media->save();
    }
  }

  /** * AJAX callback to send the new media item(s) to the media library. * * @param array $form * The complete form. * @param \Drupal\Core\Form\FormStateInterface $form_state * The current form state. * * @return array|\Drupal\Core\Ajax\AjaxResponse * The form array if there are validation errors, or an AJAX response to add * the created items to the current selection. */
Home | Imprint | This part of the site doesn't use cookies.