if ($is_remove_button) { $media_item = Media::
load($field_state['removed_item_id'
]);
$announcement =
$media_item->
access('view label'
) ?
new TranslatableMarkup('@label has been removed.',
['@label' =>
$media_item->
label()]) :
new TranslatableMarkup('Media has been removed.'
);
} else { $new_items =
count(static::
getNewMediaItems($element,
$form_state));
$announcement = \Drupal::
translation()->
formatPlural($new_items, 'Added one media item.', 'Added @count media items.'
);
} $response =
new AjaxResponse();
$response->
addCommand(new ReplaceCommand("#
$wrapper_id",
$element));
$response->
addCommand(new AnnounceCommand($announcement));
// When the remove button is clicked, shift focus to the next remove button.
// When the last item is deleted, we no longer have a selection and shift
// the focus to the open button.
$removed_last =
$is_remove_button && !
count($field_state['items'
]);
if ($is_remove_button && !
$removed_last) { // Find the next media item by weight. The weight of the removed item is
// added to the field state when it is removed in ::removeItem(). If there
// is no item with a bigger weight, we automatically shift the focus to
// the previous media item.
// @see ::removeItem()