// Allow the media library to be opened even if there are form errors.
'#limit_validation_errors' =>
[],
];
// When the user returns from the modal to the widget, we want to shift the
// focus back to the open button. If the user is not allowed to add more
// items, the button needs to be disabled. Since we can't shift the focus to
// disabled elements, the focus is set back to the open button via
// JavaScript by adding the 'data-disabled-focus' attribute.
// @see Drupal.behaviors.MediaLibraryWidgetDisableButton
if (!
$cardinality_unlimited &&
$remaining === 0
) { $triggering_element =
$form_state->
getTriggeringElement();
if ($triggering_element && ($trigger_parents =
$triggering_element['#array_parents'
]) &&
end($trigger_parents) === 'media_library_update_widget'
) { // The widget is being rebuilt from a selection change.
$element['open_button'
]['#attributes'
]['data-disabled-focus'
] = 'true';
$element['open_button'
]['#attributes'
]['class'
][] = 'visually-hidden';
} else { // The widget is being built without a selection change, so we can just
// set the item to disabled now, there is no need to set the focus
// first.
$element['open_button'
]['#disabled'
] = TRUE;
$element['open_button'
]['#attributes'
]['class'
][] = 'visually-hidden';
}