diff --git a/core/modules/media_library/css/media_library.theme.css b/core/modules/media_library/css/media_library.theme.css index 316e924623..1b00001d42 100644 --- a/core/modules/media_library/css/media_library.theme.css +++ b/core/modules/media_library/css/media_library.theme.css @@ -356,6 +356,11 @@ background-position: left 0; } +.media-library-add-form .media-library-add-form__remove-button:focus { + color: #787878; + border: 0; +} + .media-library-add-form .media-library-add-form__remove-button:hover { color: #e00; border: 0; diff --git a/core/modules/media_library/src/Form/AddFormBase.php b/core/modules/media_library/src/Form/AddFormBase.php index e58907f489..4df0fc314e 100644 --- a/core/modules/media_library/src/Form/AddFormBase.php +++ b/core/modules/media_library/src/Form/AddFormBase.php @@ -179,6 +179,9 @@ public function buildForm(array $form, FormStateInterface $form_state) { * The element containing the required fields sub-form. */ protected function buildEntityFormElement(MediaInterface $media, array $form, FormStateInterface $form_state, $delta) { + // We need to make sure each button has a unique name attribute. The default + // name for button elements is 'op'. If the name is not unique, the + // triggering element is not set correctly. $parents = $form['#parents']; $id_suffix = $parents ? '-' . implode('-', $parents) : ''; @@ -355,8 +358,7 @@ public function removeButtonSubmit(array $form, FormStateInterface $form_state) // Retrieve the delta of the media items from the parents of the remove // button. $triggering_element = $form_state->getTriggeringElement(); - $delta_slice = array_slice($triggering_element['#array_parents'], -2, 1); - $delta = reset($delta_slice); + $delta = array_slice($triggering_element['#array_parents'], -2, 1)[0]; // Update the list of added media items from the form state. $added_media = $form_state->get('media'); unset($added_media[$delta]);