You are here

public static function MediaLibrary::elementValidateMediaLibrary in Media Library Form API Element 8

Same name and namespace in other branches
  1. 2.x src/Element/MediaLibrary.php \Drupal\media_library_form_element\Element\MediaLibrary::elementValidateMediaLibrary()

Extract the proper portion of our default_value.

Parameters

array $element: The render element.

\Drupal\Core\Form\FormStateInterface $form_state: The form state object.

array $complete_form: The complete form render array.

File

src/Element/MediaLibrary.php, line 306

Class

MediaLibrary
Provides a Media library form element.

Namespace

Drupal\media_library_form_element\Element

Code

public static function elementValidateMediaLibrary(array &$element, FormStateInterface $form_state, array &$complete_form) {
  $value = NULL;
  if (!empty($element['#value'])) {
    $value = $element['#value'];
    if (isset($value['media_library_selection'])) {
      $value = $value['media_library_selection'];
    }
  }
  $form_state
    ->setValueForElement($element, $value);
}