You are here

function seven_views_pre_render in Drupal 9

Same name and namespace in other branches
  1. 8 core/themes/seven/seven.theme \seven_views_pre_render()

Implements hook_views_pre_render().

File

core/themes/seven/seven.theme, line 342
Functions to support theming in the Seven theme.

Code

function seven_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',
        ]);
      }
      if (array_key_exists('delete_media', $view->field)) {
        $add_classes($view->field['delete_media']->options['alter']['link_class'], [
          'media-library-item__remove',
        ]);
      }
    }
    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',
        ]);
      }
    }
  }
}