Files
cdesai_emulsify/includes/view.inc
T

94 lines
3.0 KiB
PHP

<?php
/**
* Implements hook_preprocess_views_view().
*/
function cdesai_emulsify_preprocess_views_view(&$vars) {
// Add the view title to selected views.
if (in_array($vars['id'], [
'page_teaser_topic',
'media_resources_tar',
'events_by_series',
'events_teaser_small',
'news_teaser_small',
'news_related_card',
])) {
$vars['title'] = [
'#markup' => $vars['view']->getTitle(),
];
}
// Add classes to the more link to selected views.
if (in_array($vars['id'], [
'events_teaser_small',
'news_teaser_small',
'media_resources_tar',
'page_teaser_topic',
]) && !empty($vars['more'])) {
$vars['more']['#options']['attributes']['class'][] = 'arrow-link';
$vars['more']['#options']['attributes']['class'][] = 'view__more-link';
}
elseif (in_array($vars['id'], [
'publication_teaser',
'news_teaser',
'news_related_card',
'page_teaser',
]) && !empty($vars['more'])) {
$vars['more']['#options']['attributes']['class'][] = 'button';
$vars['more']['#options']['attributes']['class'][] = 'button--secondary';
}
}
/**
* Implements hook_preprocess_views_view__HOOK().
*/
function cdesai_emulsify_preprocess_views_view__events_by_series(&$vars) {
if (!empty($vars['attachment_before']) &&
!empty($vars['attachment_before'][0])
) {
$attachment_before = $vars['attachment_before'][0]['#view'];
$vars['attachment_before_rows'] = $attachment_before->total_rows;
}
}
/**
* Implements hook_form_FORM_ID_alter().
*/
function cdesai_emulsify_form_views_exposed_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $formState) {
// Group start and end date within a fieldset.
if (!empty($form['#id']) &&
in_array($form['#id'], ['views-exposed-form-news-teaser-list-search-news']) &&
!empty($form['published_date'])
) {
$published_date_range = [
'#type' => 'fieldset',
'#name' => 'published_date_range',
'#title' => t('Published Date'),
'published_date' => $form['published_date'],
];
// Since the order of the displayed exposed form options more or less
// follows the array order, insert the new fieldset next to the start date.
$published_date_index = array_search('published_date', array_keys($form));
$form = array_merge(
array_slice($form, 0, $published_date_index),
['published_date_range' => $published_date_range],
array_slice($form, $published_date_index)
);
unset($form['published_date']);
}
}
/**
* Implements hook_preprocess_views_exposed_form
*/
function cdesai_emulsify_preprocess_views_exposed_form(&$vars) {
$form = &$vars['form'];
if (!empty($form['published_date_range'])) {
// Views doesn't add labels to exposed form elements until the preprocess
// function, so we do the same thing here for elements moved into a fieldset.
// @see template_preprocess_views_exposed_form
$form['published_date_range']['published_date']['min']['#title'] = t('Start');
$form['published_date_range']['published_date']['max']['#title'] = t('End');
}
}