function claro_views_pre_render

Same name in other branches
  1. 8.9.x core/themes/claro/claro.theme \claro_views_pre_render()
  2. 10 core/themes/claro/claro.theme \claro_views_pre_render()
  3. 11.x core/themes/claro/claro.theme \claro_views_pre_render()

Implements hook_views_pre_render().

File

core/themes/claro/claro.theme, line 1454

Code

function claro_views_pre_render(ViewExecutable $view) {
    $add_classes = function (&$option, array $classes_to_add) {
        $classes = preg_split('/\\s+/', $option);
        $classes = array_filter($classes);
        $classes = array_merge($classes, $classes_to_add);
        $option = implode(' ', array_unique($classes));
    };
    if ($view->id() === 'media_library') {
        if ($view->display_handler->options['defaults']['css_class']) {
            $add_classes($view->displayHandlers
                ->get('default')->options['css_class'], [
                'media-library-view',
            ]);
        }
        else {
            $add_classes($view->display_handler->options['css_class'], [
                'media-library-view',
            ]);
        }
        if ($view->current_display === 'page') {
            if (array_key_exists('media_bulk_form', $view->field)) {
                $add_classes($view->field['media_bulk_form']->options['element_class'], [
                    'media-library-item__click-to-select-checkbox',
                ]);
            }
            if (array_key_exists('rendered_entity', $view->field)) {
                $add_classes($view->field['rendered_entity']->options['element_class'], [
                    'media-library-item__content',
                ]);
            }
            if (array_key_exists('edit_media', $view->field)) {
                $add_classes($view->field['edit_media']->options['alter']['link_class'], [
                    'media-library-item__edit',
                ]);
                $add_classes($view->field['edit_media']->options['alter']['link_class'], [
                    'icon-link',
                ]);
            }
            if (array_key_exists('delete_media', $view->field)) {
                $add_classes($view->field['delete_media']->options['alter']['link_class'], [
                    'media-library-item__remove',
                ]);
                $add_classes($view->field['delete_media']->options['alter']['link_class'], [
                    'icon-link',
                ]);
            }
        }
        elseif (strpos($view->current_display, 'widget') === 0) {
            if (array_key_exists('rendered_entity', $view->field)) {
                $add_classes($view->field['rendered_entity']->options['element_class'], [
                    'media-library-item__content',
                ]);
            }
            if (array_key_exists('media_library_select_form', $view->field)) {
                $add_classes($view->field['media_library_select_form']->options['element_wrapper_class'], [
                    'media-library-item__click-to-select-checkbox',
                ]);
            }
            if ($view->display_handler->options['defaults']['css_class']) {
                $add_classes($view->displayHandlers
                    ->get('default')->options['css_class'], [
                    'media-library-view--widget',
                ]);
            }
            else {
                $add_classes($view->display_handler->options['css_class'], [
                    'media-library-view--widget',
                ]);
            }
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.