Class toevoegen aan views more link

In dit codefragment laat ik zien hoe je een class kan toevoegen aan een "more" link in Drupal 8 door template_preprocess_views_view() te gebruiken in je theme THEMENAME.theme bestand:

/**
 * Implements template_preprocess_views_view()
 * @param array $variables
 */
function THEMENAME_preprocess_views_view(&$variables)
{
    $view = $variables['view'];
    if ($view->id() == 'VIEW_ID') {
        $variables['more']['#options']['attributes']['class'][] = 'class_css';
    }
}

// Example how to add a class to more link in specific page or block:

/**
 * @param $variables
 */
function THEMENAME_preprocess_views_view(&$variables)
{
    $view = $variables['view'];
    switch ($view->storage->id()) {
        case 'news':
            if ($view->current_display == 'page_1' || $view->current_display == 'block_1')  {
                $variables['more']['#options']['attributes']['class'] = 'btn btn-primary';
            }
    }
}
back_snippet