function MediaLibraryInceptionWidget::elementValidate
File
- 
              core/modules/ media_library/ tests/ modules/ media_library_test_widget/ src/ Plugin/ Field/ FieldWidget/ MediaLibraryInceptionWidget.php, line 43 
Class
- MediaLibraryInceptionWidget
- Plugin implementation of the 'media_library_inception_widget' widget.
Namespace
Drupal\media_library_test_widget\Plugin\Field\FieldWidgetCode
public function elementValidate($element, FormStateInterface $form_state, $form) {
  $field_name = $element['#field_name'];
  $entity = $form_state->getFormObject()
    ->getEntity();
  $input = $form_state->getUserInput();
  if (!empty($input['_triggering_element_name']) && strpos($input['_triggering_element_name'], 'media-library-update') !== FALSE) {
    // This will validate a required field before an upload is completed.
    $display = EntityFormDisplay::collectRenderDisplay($entity, 'edit');
    $display->extractFormValues($entity, $form, $form_state);
    $display->validateFormValues($entity, $form, $form_state);
  }
  $form_value = $form_state->getValue($field_name);
  if (!empty($form_value['media_library_selection'])) {
    $entity->set($field_name, $form_value['media_library_selection']);
  }
}Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.
