You are here

function gin_lb_views_pre_render in Gin Layout Builder 1.0.x

Implements hook_views_pre_render().

File

./gin_lb.module, line 112
Provides hooks for gin_lb module.

Code

function gin_lb_views_pre_render(ViewExecutable $view) {
  if (gin_lb_is_valid_theme() === FALSE) {
    return;
  }
  $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',
        ]);
      }
    }
  }
}