You are here

function opigno_catalog_preprocess_views_view in Opigno training catalog 8

Adds assets to view.

Implements hook_preprocess_HOOK().

File

./opigno_catalog.module, line 98
Contains opigno_catalog.module.

Code

function opigno_catalog_preprocess_views_view(&$variables) {
  if ($variables['id'] == 'opigno_training_catalog') {
    $style = \Drupal::service('opigno_catalog.get_style')
      ->getStyle();

    // Add style class to view.
    $variables['attributes']['class'][] = $style == 'line' ? 'style-line' : 'style-block';

    // Add library.
    $variables['view']->element['#attached']['library'][] = 'opigno_catalog/view_style';

    // Add switcher.
    $variables['header']['view-style'] = [
      '#theme' => 'view_style',
      '#weight' => 0,
    ];
  }
}