1,6c1,4 < diff --git a/core/modules/media/config/install/core.entity_view_mode.media.full.yml b/core/modules/media/config/optional/core.entity_form_mode.media.add_inline.yml < similarity index 60% < copy from core/modules/media/config/install/core.entity_view_mode.media.full.yml < copy to core/modules/media/config/optional/core.entity_form_mode.media.add_inline.yml < index dfdbb3a..e082019 100644 < --- a/core/modules/media/config/install/core.entity_view_mode.media.full.yml --- > diff --git a/core/modules/media/config/optional/core.entity_form_mode.media.add_inline.yml b/core/modules/media/config/optional/core.entity_form_mode.media.add_inline.yml > new file mode 100644 > index 0000000000..e082019a82 > --- /dev/null 8,10c6,7 < @@ -1,9 +1,9 @@ < langcode: en < -status: false --- > @@ -0,0 +1,9 @@ > +langcode: en 12,16c9,11 < dependencies: < module: < - media < -id: media.full < -label: 'Full content' --- > +dependencies: > + module: > + - media 19,20c14,15 < targetEntityType: media < cache: true --- > +targetEntityType: media > +cache: true 27c22 < index 0000000..4a9a28b --- > index 0000000000..4df28a8e5b 30c25 < @@ -0,0 +1,95 @@ --- > @@ -0,0 +1,79 @@ 109,124d103 < + /** < + * {@inheritdoc} < + */ < + public static function uploadAjaxCallback(&$form, FormStateInterface &$form_state, Request $request) { < + // Clear our fake error. < + $errors = drupal_get_messages('error'); < + $request->getSession()->getBag('flashes')->clear(); < + foreach ($errors['error'] as $error) { < + if ($error !== 'Dummy inline form error') { < + drupal_set_message($error, 'error'); < + } < + } < + < + return parent::uploadAjaxCallback($form, $form_state, $request); < + } < + 127c106 < index dc8e0dc..a94f4a6 100644 --- > index dc8e0dcf0f..a94f4a6b85 100644 140c119 < index 0000000..b268f6c --- > index 0000000000..422a9e9878 143c122 < @@ -0,0 +1,238 @@ --- > @@ -0,0 +1,279 @@ 256a236,241 > + elseif (!empty($entity_form[$field_name])) { > + // Elements with "#required" key set will always be validated, even if > + // 'limit_validation_errors' is set. Disable their validation here, we > + // will enforce validation happens inside the real submit handler. > + $entity_form[$field_name] = $this->disableElementChildrenValidation($entity_form[$field_name]); > + } 269a255,264 > + // If this is an image media entity, and the image field on that entity has > + // either "Alt field required" or "Title field required", we take care of > + // that in > + // @see \Drupal\media\Plugin\Field\FieldWidget\MediaImageWidget::process(). > + foreach (['#alt_field_required', '#title_field_required'] as $extra_image_field_attribute) { > + if (!empty($entity_form[$source_field]['widget'][0][$extra_image_field_attribute])) { > + $entity_form[$source_field]['widget'][0][$extra_image_field_attribute] = FALSE; > + } > + } > + 341a337,361 > + * Bypass validation in all children of a given element. > + * > + * @param array $element > + * The element array. > + * > + * @return array > + * The same element array, after recursively checking all its children and > + * setting "#validated" => TRUE in all required elements. > + */ > + private function disableElementChildrenValidation(array $element) { > + foreach (Element::children($element) as $key) { > + if (isset($element[$key]) && $element[$key]) { > + $element[$key] = $this->disableElementChildrenValidation($element[$key]); > + } > + } > + > + if (!empty($element['#needs_validation']) || !empty($element['#required'])) { > + $element['#validated'] = TRUE; > + } > + > + return $element; > + } > + > + > + /** 384c404 < index 0000000..5d87cd2 --- > index 0000000000..51d3d79dbb 387c407 < @@ -0,0 +1,429 @@ --- > @@ -0,0 +1,415 @@ 683,696d702 < + < + // Prevent the added form elements from failing the required fields < + // validation when the form is first processed. < + $element['upload_button']['#limit_validation_errors'] = []; < + $element['remove_button']['#limit_validation_errors'] = []; < + // We set a "fake" error here to prevent the form rebuilding process, < + // and we remove this error message later in < + // \Drupal\media\Element\MediaManagedFile::uploadAjaxCallback(). < + // @TODO Fgure out a better way of doing this. < + $remove_operation = !empty($form_state->getUserInput()['_triggering_element_value']) && $form_state->getUserInput()['_triggering_element_value'] === 'Remove'; < + if (\Drupal::request()->query->has(FormBuilder::AJAX_FORM_REQUEST) && !$remove_operation) { < + $non_existent_element = ['#parents' => []]; < + $form_state->setError($non_existent_element, 'Dummy inline form error'); < + } 819c825 < index 0000000..e69de29 --- > index 0000000000..e69de29bb2 822c828 < index 0000000..e69de29 --- > index 0000000000..e69de29bb2 825c831 < index 0000000..f82b523 --- > index 0000000000..9147ae0dfc 828c834 < @@ -0,0 +1,274 @@ --- > @@ -0,0 +1,276 @@ 998a1005,1006 > + // Since cardinality is -1, we should be allowed to upload another file now. > + $assert_session->elementExists('css', 'input[name="files[field_media_reference_1][]"]');