if ($form_state::
hasAnyErrors()) { return $form;
} $media_ids =
array_map(function DMediaInterface
$media) { return $media->
id();
},
$this->
getAddedMediaItems($form_state));
$selected_count =
$this->
getSelectedMediaItemCount($media_ids,
$form_state);
$response =
new AjaxResponse();
$response->
addCommand(new UpdateSelectionCommand($media_ids));
$media_id_to_focus =
array_pop($media_ids);
$response->
addCommand(new ReplaceCommand('#media-library-add-form-wrapper',
$this->
buildMediaLibraryUi($form_state)));
$response->
addCommand(new InvokeCommand("#media-library-content [value=
$media_id_to_focus]", 'focus'
));
$available_slots =
$this->
getMediaLibraryState($form_state)->
getAvailableSlots();
if ($available_slots > 0 &&
$selected_count >
$available_slots) { $warning =
$this->
formatPlural($selected_count -
$available_slots, 'There are currently @total items selected. The maximum number of items for the field is @max. Please remove @count item from the selection.', 'There are currently @total items selected. The maximum number of items for the field is @max. Please remove @count items from the selection.',
[ '@total' =>
$selected_count,
'@max' =>
$available_slots,
]);
$response->
addCommand(new MessageCommand($warning, '#media-library-messages',
['type' => 'warning'
]));
}