public function MediaLibraryInceptionWidget::elementValidate in Drupal 9
Same name and namespace in other branches
- 8 core/modules/media_library/tests/modules/media_library_test_widget/src/Plugin/Field/FieldWidget/MediaLibraryInceptionWidget.php \Drupal\media_library_test_widget\Plugin\Field\FieldWidget\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']);
}
}