$response =
new AjaxResponse();
$error = \Drupal::
translation()->
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($error, '#media-library-messages',
['type' => 'error'
]));
return $response;
} return \Drupal::
service('media_library.opener_resolver'
) ->
get($state) ->
getSelectionResponse($state,
$selected_ids) ->
addCommand(new CloseDialogCommand());
} /**
* {@inheritdoc}
*/
public function viewsFormValidate(array &
$form, FormStateInterface
$form_state) { $selected =
array_filter($form_state->
getValue($this->options
['id'
]));
if (empty($selected)) { $form_state->
setErrorByName('',
$this->
t('No items selected.'
));
} }