function media_library_views_pre_render
Same name in other branches
- 9 core/modules/media_library/media_library.module \media_library_views_pre_render()
- 8.9.x core/modules/media_library/media_library.module \media_library_views_pre_render()
- 10 core/modules/media_library/media_library.module \media_library_views_pre_render()
Implements hook_views_pre_render().
File
-
core/
modules/ media_library/ media_library.module, line 152
Code
function media_library_views_pre_render(ViewExecutable $view) {
$add_classes = function (&$option, array $classes_to_add) {
$classes = $option ? preg_split('/\\s+/', trim($option)) : [];
$classes = array_filter($classes);
$classes = array_merge($classes, $classes_to_add);
$option = implode(' ', array_unique($classes));
};
if ($view->id() === 'media_library') {
if ($view->current_display === 'page') {
$add_classes($view->style_plugin->options['row_class'], [
'js-media-library-item',
'js-click-to-select',
]);
if (array_key_exists('media_bulk_form', $view->field)) {
$add_classes($view->field['media_bulk_form']->options['element_class'], [
'js-click-to-select-checkbox',
]);
}
}
elseif (str_starts_with($view->current_display, 'widget')) {
if (array_key_exists('media_library_select_form', $view->field)) {
$add_classes($view->field['media_library_select_form']->options['element_wrapper_class'], [
'js-click-to-select-checkbox',
]);
}
$add_classes($view->display_handler->options['css_class'], [
'js-media-library-view',
]);
}
$add_classes($view->style_plugin->options['row_class'], [
'js-media-library-item',
'js-click-to-select',
]);
if ($view->display_handler->options['defaults']['css_class']) {
$add_classes($view->displayHandlers
->get('default')->options['css_class'], [
'js-media-library-view',
]);
}
else {
$add_classes($view->display_handler->options['css_class'], [
'js-media-library-view',
]);
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.