function opigno_catalog_preprocess_views_view__opigno_training_catalog in Opigno training catalog 3.x
Implements hook_preprocess_HOOK().
File
- ./
opigno_catalog.module, line 75 - Contains opigno_catalog.module.
Code
function opigno_catalog_preprocess_views_view__opigno_training_catalog(&$variables) {
// Add the "Create new training" link.
$new_training_url = Url::fromRoute('entity.group.add_form', [
'group_type' => 'learning_path',
]);
if ($new_training_url
->access()) {
$options = [
'attributes' => [
'class' => [
'btn',
'btn-bg',
'btn-rounded',
],
],
];
$new_training_url
->setOptions($options);
$variables['new_training_link'] = Link::fromTextAndUrl(t('Create new training'), $new_training_url);
}
// Add the fake sort select. The sorting will be triggered with js because of
// the design.
$variables['fake_sort'] = [
'#type' => 'select',
'#options' => [
'created_DESC' => t('Newest'),
'created_ASC' => t('Oldest'),
'weight_ASC' => t('Shortest'),
'weight_DESC' => t('Longest'),
'label_ASC' => t('A to Z'),
'label_DESC' => t('Z to A'),
],
'#default_value' => 'created_DESC',
'#theme_wrappers' => [],
'#attributes' => [
'id' => 'opigno-fake-sort',
'class' => [
'form-select',
'selectpicker',
],
],
];
// Add style class to view.
$style = \Drupal::service('opigno_catalog.get_style')
->getStyle();
$variables['attributes']['class'][] = $style === 'line' ? 'style-line' : 'style-block';
// Add library.
$variables['view']->element['#attached']['library'][] = 'opigno_catalog/view_style';
}