2009-05-17 11:16:51 +00:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @file
|
|
|
|
|
* Preprocessors and helper functions to make theming easier.
|
|
|
|
|
*/
|
|
|
|
|
|
2014-02-13 11:53:32 +00:00
|
|
|
|
use Drupal\Component\Utility\String;
|
2013-06-15 07:19:01 +00:00
|
|
|
|
use Drupal\Component\Utility\Xss;
|
2013-05-25 20:12:45 +00:00
|
|
|
|
use Drupal\Core\Language\Language;
|
2012-09-04 14:20:57 +00:00
|
|
|
|
use Drupal\Core\Template\Attribute;
|
2013-11-14 04:57:56 +00:00
|
|
|
|
use Drupal\views\Form\ViewsForm;
|
2012-09-23 19:09:23 +00:00
|
|
|
|
use Drupal\views\ViewExecutable;
|
2012-09-04 14:20:57 +00:00
|
|
|
|
|
2009-05-17 11:16:51 +00:00
|
|
|
|
/**
|
2013-05-25 05:13:58 +00:00
|
|
|
|
* Prepares variables for view templates.
|
|
|
|
|
*
|
|
|
|
|
* Default template: views-view.html.twig.
|
|
|
|
|
*
|
2013-07-13 10:29:57 +00:00
|
|
|
|
* @param array $variables
|
2013-05-25 05:13:58 +00:00
|
|
|
|
* An associative array containing:
|
|
|
|
|
* - view: The ViewExecutable object.
|
2009-05-17 11:16:51 +00:00
|
|
|
|
*/
|
2013-07-13 10:29:57 +00:00
|
|
|
|
function template_preprocess_views_view(&$variables) {
|
|
|
|
|
$view = $variables['view'];
|
2009-05-17 11:16:51 +00:00
|
|
|
|
|
2013-07-13 10:29:57 +00:00
|
|
|
|
$variables['rows'] = (!empty($view->result) || $view->style_plugin->evenEmpty()) ? $view->style_plugin->render($view->result) : array();
|
2012-12-04 15:49:07 +00:00
|
|
|
|
// Force a render array so CSS/JS can be added.
|
2013-07-13 10:29:57 +00:00
|
|
|
|
if (!is_array($variables['rows'])) {
|
|
|
|
|
$variables['rows'] = array('#markup' => $variables['rows']);
|
2012-12-04 15:49:07 +00:00
|
|
|
|
}
|
2009-05-17 11:16:51 +00:00
|
|
|
|
|
2013-07-13 10:29:57 +00:00
|
|
|
|
$variables['css_name'] = drupal_clean_css_identifier($view->storage->id());
|
|
|
|
|
$variables['id'] = $view->storage->id();
|
|
|
|
|
$variables['display_id'] = $view->current_display;
|
2009-05-17 11:16:51 +00:00
|
|
|
|
|
2013-05-25 05:13:58 +00:00
|
|
|
|
// Basic classes.
|
2013-07-13 10:29:57 +00:00
|
|
|
|
$variables['css_class'] = '';
|
2012-05-18 14:38:33 +00:00
|
|
|
|
|
2013-07-13 10:29:57 +00:00
|
|
|
|
$variables['attributes']['class'] = array();
|
|
|
|
|
$variables['attributes']['class'][] = 'view';
|
|
|
|
|
$variables['attributes']['class'][] = 'view-' . drupal_clean_css_identifier($variables['id']);
|
|
|
|
|
$variables['attributes']['class'][] = 'view-id-' . $variables['id'];
|
|
|
|
|
$variables['attributes']['class'][] = 'view-display-id-' . $variables['display_id'];
|
2009-05-17 11:16:51 +00:00
|
|
|
|
|
2012-08-30 09:23:13 +00:00
|
|
|
|
$css_class = $view->display_handler->getOption('css_class');
|
2009-05-17 11:16:51 +00:00
|
|
|
|
if (!empty($css_class)) {
|
2013-07-13 10:29:57 +00:00
|
|
|
|
$variables['css_class'] = preg_replace('/[^a-zA-Z0-9- ]/', '-', $css_class);
|
|
|
|
|
$variables['attributes']['class'][] = $variables['css_class'];
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-12-08 23:11:44 +00:00
|
|
|
|
$empty = empty($view->result);
|
2013-07-13 10:29:57 +00:00
|
|
|
|
$variables['header'] = $view->display_handler->renderArea('header', $empty);
|
|
|
|
|
$variables['footer'] = $view->display_handler->renderArea('footer', $empty);
|
|
|
|
|
$variables['empty'] = $empty ? $view->display_handler->renderArea('empty', $empty) : FALSE;
|
2009-05-17 11:16:51 +00:00
|
|
|
|
|
2013-07-13 10:29:57 +00:00
|
|
|
|
$variables['exposed'] = !empty($view->exposed_widgets) ? $view->exposed_widgets : '';
|
|
|
|
|
$variables['more'] = $view->display_handler->renderMoreLink();
|
|
|
|
|
$variables['feed_icon'] = !empty($view->feed_icon) ? $view->feed_icon : '';
|
2009-05-17 11:16:51 +00:00
|
|
|
|
|
2013-07-13 10:29:57 +00:00
|
|
|
|
$variables['pager'] = '';
|
2009-05-17 11:16:51 +00:00
|
|
|
|
|
|
|
|
|
// @todo: Figure out whether this belongs into views_ui_preprocess_views_view.
|
|
|
|
|
// Render title for the admin preview.
|
2013-07-13 10:29:57 +00:00
|
|
|
|
$variables['title'] = !empty($view->views_ui_context) ? filter_xss_admin($view->getTitle()) : '';
|
2009-05-17 11:16:51 +00:00
|
|
|
|
|
2012-08-30 09:23:13 +00:00
|
|
|
|
if ($view->display_handler->renderPager()) {
|
2009-05-17 11:16:51 +00:00
|
|
|
|
$exposed_input = isset($view->exposed_raw_input) ? $view->exposed_raw_input : NULL;
|
2013-07-13 10:29:57 +00:00
|
|
|
|
$variables['pager'] = $view->renderPager($exposed_input);
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-12-09 16:56:41 +00:00
|
|
|
|
if (!empty($view->attachment_before)) {
|
2013-07-13 10:29:57 +00:00
|
|
|
|
$variables['attachment_before'] = $view->attachment_before;
|
2012-12-09 16:56:41 +00:00
|
|
|
|
}
|
|
|
|
|
else {
|
2013-07-13 10:29:57 +00:00
|
|
|
|
$variables['attachment_before'] = array();
|
2012-12-09 16:56:41 +00:00
|
|
|
|
}
|
|
|
|
|
if (!empty($view->attachment_after)) {
|
2013-07-13 10:29:57 +00:00
|
|
|
|
$variables['attachment_after'] = $view->attachment_after;
|
2012-12-09 16:56:41 +00:00
|
|
|
|
}
|
|
|
|
|
else {
|
2013-07-13 10:29:57 +00:00
|
|
|
|
$variables['attachment_after'] = array();
|
2012-12-09 16:56:41 +00:00
|
|
|
|
}
|
2009-05-17 11:16:51 +00:00
|
|
|
|
|
|
|
|
|
// Add contextual links to the view. We need to attach them to the dummy
|
|
|
|
|
// $view_array variable, since contextual_preprocess() requires that they be
|
|
|
|
|
// attached to an array (not an object) in order to process them. For our
|
|
|
|
|
// purposes, it doesn't matter what we attach them to, since once they are
|
|
|
|
|
// processed by contextual_preprocess() they will appear in the $title_suffix
|
2013-05-25 05:13:58 +00:00
|
|
|
|
// variable (which we will then render in views-view.html.twig).
|
2013-07-13 10:29:57 +00:00
|
|
|
|
views_add_contextual_links($variables['view_array'], 'view', $view, $view->current_display);
|
2009-05-17 11:16:51 +00:00
|
|
|
|
|
|
|
|
|
// Attachments are always updated with the outer view, never by themselves,
|
|
|
|
|
// so they do not have dom ids.
|
|
|
|
|
if (empty($view->is_attachment)) {
|
2013-05-25 05:13:58 +00:00
|
|
|
|
// Our JavaScript needs to have some means to find the HTML belonging to
|
|
|
|
|
// this view.
|
2009-05-17 11:16:51 +00:00
|
|
|
|
//
|
|
|
|
|
// It is true that the DIV wrapper has classes denoting the name of the view
|
|
|
|
|
// and its display ID, but this is not enough to unequivocally match a view
|
|
|
|
|
// with its HTML, because one view may appear several times on the page. So
|
2013-05-25 05:13:58 +00:00
|
|
|
|
// we set up a hash with the current time, $dom_id, to issue a "unique"
|
|
|
|
|
// identifier for each view. This identifier is written to both
|
2013-09-21 23:39:42 +00:00
|
|
|
|
// drupalSettings and the DIV wrapper.
|
2013-07-13 10:29:57 +00:00
|
|
|
|
$variables['dom_id'] = $view->dom_id;
|
|
|
|
|
$variables['attributes']['class'][] = 'view-dom-id-' . $variables['dom_id'];
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If using AJAX, send identifying data about this view.
|
2013-02-05 13:03:02 +00:00
|
|
|
|
if ($view->ajaxEnabled() && empty($view->is_attachment) && empty($view->live_preview)) {
|
2009-05-17 11:16:51 +00:00
|
|
|
|
$settings = array(
|
|
|
|
|
'views' => array(
|
|
|
|
|
'ajax_path' => url('views/ajax'),
|
|
|
|
|
'ajaxViews' => array(
|
2013-07-13 10:29:57 +00:00
|
|
|
|
'views_dom_id:' . $variables['dom_id'] => array(
|
2013-01-19 05:10:42 +00:00
|
|
|
|
'view_name' => $view->storage->id(),
|
2009-05-17 11:16:51 +00:00
|
|
|
|
'view_display_id' => $view->current_display,
|
2014-02-13 11:53:32 +00:00
|
|
|
|
'view_args' => String::checkPlain(implode('/', $view->args)),
|
|
|
|
|
'view_path' => String::checkPlain(current_path()),
|
2012-08-29 19:36:52 +00:00
|
|
|
|
'view_base_path' => $view->getPath(),
|
2013-07-13 10:29:57 +00:00
|
|
|
|
'view_dom_id' => $variables['dom_id'],
|
2009-05-17 11:16:51 +00:00
|
|
|
|
// To fit multiple views on a page, the programmer may have
|
|
|
|
|
// overridden the display's pager_element.
|
2013-05-28 20:47:22 +00:00
|
|
|
|
'pager_element' => isset($view->pager) ? $view->pager->getPagerId() : 0,
|
2009-05-17 11:16:51 +00:00
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
2012-12-04 15:49:07 +00:00
|
|
|
|
$view->element['#attached']['js'][] = array('type' => 'setting', 'data' => $settings);
|
|
|
|
|
$view->element['#attached']['library'][] = array('views', 'views.ajax');
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-25 05:13:58 +00:00
|
|
|
|
// If form fields were found in the view, reformat the view output as a form.
|
2014-02-13 09:18:54 +00:00
|
|
|
|
if ($view->hasFormElements()) {
|
2012-12-08 23:11:44 +00:00
|
|
|
|
// Copy the rows so as not to modify them by reference when rendering.
|
2013-07-13 10:29:57 +00:00
|
|
|
|
$rows = $variables['rows'];
|
2014-02-07 07:15:09 +00:00
|
|
|
|
// Only render row output if there are rows. Otherwise, render the empty
|
|
|
|
|
// region.
|
|
|
|
|
if (!empty($rows)) {
|
|
|
|
|
$output = drupal_render($rows);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$empty = $variables['empty'];
|
|
|
|
|
$output = drupal_render($empty);
|
|
|
|
|
}
|
2013-11-14 04:57:56 +00:00
|
|
|
|
|
|
|
|
|
$container = \Drupal::getContainer();
|
|
|
|
|
$form_object = new ViewsForm($container->get('controller_resolver'), $container->get('url_generator'), $container->get('request'), $view->storage->id(), $view->current_display);
|
|
|
|
|
$form = \Drupal::formBuilder()->getForm($form_object, $view, $output);
|
2009-05-17 11:16:51 +00:00
|
|
|
|
// The form is requesting that all non-essential views elements be hidden,
|
|
|
|
|
// usually because the rendered step is not a view result.
|
|
|
|
|
if ($form['show_view_elements']['#value'] == FALSE) {
|
2013-07-13 10:29:57 +00:00
|
|
|
|
$variables['header'] = '';
|
|
|
|
|
$variables['exposed'] = '';
|
|
|
|
|
$variables['pager'] = '';
|
|
|
|
|
$variables['footer'] = '';
|
|
|
|
|
$variables['more'] = '';
|
|
|
|
|
$variables['feed_icon'] = '';
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
2013-07-13 10:29:57 +00:00
|
|
|
|
$variables['rows'] = $form;
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2013-05-25 00:03:24 +00:00
|
|
|
|
* Prepares variables for views fields templates.
|
|
|
|
|
*
|
|
|
|
|
* Default template: views-view-fields.html.twig.
|
|
|
|
|
*
|
2013-07-13 10:29:57 +00:00
|
|
|
|
* @param array $variables
|
2013-05-25 00:03:24 +00:00
|
|
|
|
* An associative array containing:
|
|
|
|
|
* - view: The view object.
|
|
|
|
|
* - options: An array of options. Each option contains:
|
|
|
|
|
* - inline: An array that contains the fields that are to be
|
|
|
|
|
* displayed inline.
|
|
|
|
|
* - default_field_elements: If default field wrapper
|
|
|
|
|
* elements are to be provided.
|
|
|
|
|
* - hide_empty: Whether the field is to be hidden if empty.
|
|
|
|
|
* - element_default_classes: If the default classes are to be added.
|
|
|
|
|
* - separator: A string to be placed between inline fields to keep them
|
|
|
|
|
* visually distinct.
|
|
|
|
|
* - row: An array containing information about the current row.
|
2009-05-17 11:16:51 +00:00
|
|
|
|
*/
|
2013-07-13 10:29:57 +00:00
|
|
|
|
function template_preprocess_views_view_fields(&$variables) {
|
|
|
|
|
$view = $variables['view'];
|
2009-05-17 11:16:51 +00:00
|
|
|
|
|
|
|
|
|
// Loop through the fields for this view.
|
|
|
|
|
$previous_inline = FALSE;
|
2013-07-13 10:29:57 +00:00
|
|
|
|
$variables['fields'] = array(); // ensure it's at least an empty array.
|
2009-05-17 11:16:51 +00:00
|
|
|
|
foreach ($view->field as $id => $field) {
|
|
|
|
|
// render this even if set to exclude so it can be used elsewhere.
|
2013-06-11 22:33:23 +00:00
|
|
|
|
$field_output = $view->style_plugin->getField($view->row_index, $id);
|
2013-06-05 06:45:09 +00:00
|
|
|
|
$empty = $field->isValueEmpty($field_output, $field->options['empty_zero']);
|
2013-07-13 10:29:57 +00:00
|
|
|
|
if (empty($field->options['exclude']) && (!$empty || (empty($field->options['hide_empty']) && empty($variables['options']['hide_empty'])))) {
|
2009-05-17 11:16:51 +00:00
|
|
|
|
$object = new stdClass();
|
2013-11-11 18:59:24 +00:00
|
|
|
|
$object->handler = $view->field[$id];
|
2013-07-13 10:29:57 +00:00
|
|
|
|
$object->inline = !empty($variables['options']['inline'][$id]);
|
2009-05-17 11:16:51 +00:00
|
|
|
|
|
2013-07-13 10:29:57 +00:00
|
|
|
|
$object->element_type = $object->handler->elementType(TRUE, !$variables['options']['default_field_elements'], $object->inline);
|
2009-05-17 11:16:51 +00:00
|
|
|
|
if ($object->element_type) {
|
2012-12-19 17:10:45 +00:00
|
|
|
|
$attributes = array();
|
2009-05-17 11:16:51 +00:00
|
|
|
|
if ($object->handler->options['element_default_classes']) {
|
2012-12-19 17:10:45 +00:00
|
|
|
|
$attributes['class'][] = 'field-content';
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-13 08:12:00 +00:00
|
|
|
|
if ($classes = $object->handler->elementClasses($view->row_index)) {
|
2012-12-19 17:10:45 +00:00
|
|
|
|
$attributes['class'][] = $classes;
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
2012-12-19 17:10:45 +00:00
|
|
|
|
$attributes = new Attribute($attributes);
|
2009-05-17 11:16:51 +00:00
|
|
|
|
|
|
|
|
|
$pre = '<' . $object->element_type;
|
2012-12-19 17:10:45 +00:00
|
|
|
|
$pre .= $attributes;
|
2009-05-17 11:16:51 +00:00
|
|
|
|
$field_output = $pre . '>' . $field_output . '</' . $object->element_type . '>';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Protect ourself somewhat for backward compatibility. This will prevent
|
|
|
|
|
// old templates from producing invalid HTML when no element type is selected.
|
|
|
|
|
if (empty($object->element_type)) {
|
|
|
|
|
$object->element_type = 'span';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$object->content = $field_output;
|
2013-07-13 10:29:57 +00:00
|
|
|
|
if (isset($view->field[$id]->field_alias) && isset($variables['row']->{$view->field[$id]->field_alias})) {
|
|
|
|
|
$object->raw = $variables['row']->{$view->field[$id]->field_alias};
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$object->raw = NULL; // make sure it exists to reduce NOTICE
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-13 10:29:57 +00:00
|
|
|
|
if (!empty($variables['options']['separator']) && $previous_inline && $object->inline && $object->content) {
|
|
|
|
|
$object->separator = filter_xss_admin($variables['options']['separator']);
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$object->class = drupal_clean_css_identifier($id);
|
|
|
|
|
|
|
|
|
|
$previous_inline = $object->inline;
|
2013-05-29 05:06:16 +00:00
|
|
|
|
$object->inline_html = $object->handler->elementWrapperType(TRUE, TRUE);
|
2013-07-13 10:29:57 +00:00
|
|
|
|
if ($object->inline_html === '' && $variables['options']['default_field_elements']) {
|
2009-05-17 11:16:51 +00:00
|
|
|
|
$object->inline_html = $object->inline ? 'span' : 'div';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Set up the wrapper HTML.
|
|
|
|
|
$object->wrapper_prefix = '';
|
|
|
|
|
$object->wrapper_suffix = '';
|
|
|
|
|
|
|
|
|
|
if ($object->inline_html) {
|
2012-12-19 17:10:45 +00:00
|
|
|
|
$attributes = array();
|
2009-05-17 11:16:51 +00:00
|
|
|
|
if ($object->handler->options['element_default_classes']) {
|
2012-12-19 17:10:45 +00:00
|
|
|
|
$attributes['class'][] = 'views-field';
|
|
|
|
|
$attributes['class'][] = 'views-field-' . $object->class;
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-29 07:43:16 +00:00
|
|
|
|
if ($classes = $object->handler->elementWrapperClasses($view->row_index)) {
|
2012-12-19 17:10:45 +00:00
|
|
|
|
$attributes['class'][] = $classes;
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
2012-12-19 17:10:45 +00:00
|
|
|
|
$attributes = new Attribute($attributes);
|
2009-05-17 11:16:51 +00:00
|
|
|
|
|
|
|
|
|
$object->wrapper_prefix = '<' . $object->inline_html;
|
2012-12-19 17:10:45 +00:00
|
|
|
|
$object->wrapper_prefix .= $attributes;
|
2009-05-17 11:16:51 +00:00
|
|
|
|
$object->wrapper_prefix .= '>';
|
|
|
|
|
$object->wrapper_suffix = '</' . $object->inline_html . '>';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Set up the label for the value and the HTML to make it easier
|
|
|
|
|
// on the template.
|
2014-02-13 11:53:32 +00:00
|
|
|
|
$object->label = String::checkPlain($view->field[$id]->label());
|
2009-05-17 11:16:51 +00:00
|
|
|
|
$object->label_html = '';
|
|
|
|
|
if ($object->label) {
|
|
|
|
|
$object->label_html .= $object->label;
|
|
|
|
|
if ($object->handler->options['element_label_colon']) {
|
|
|
|
|
$object->label_html .= ': ';
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-13 10:29:57 +00:00
|
|
|
|
$object->elementLabelType = $object->handler->elementLabelType(TRUE, !$variables['options']['default_field_elements']);
|
2013-06-10 13:54:59 +00:00
|
|
|
|
if ($object->elementLabelType) {
|
2012-12-19 17:10:45 +00:00
|
|
|
|
$attributes = array();
|
2009-05-17 11:16:51 +00:00
|
|
|
|
if ($object->handler->options['element_default_classes']) {
|
2012-12-19 17:10:45 +00:00
|
|
|
|
$attributes['class'][] = 'views-label';
|
|
|
|
|
$attributes['class'][] = 'views-label-' . $object->class;
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-29 13:27:16 +00:00
|
|
|
|
$element_label_class = $object->handler->elementLabelClasses($view->row_index);
|
2009-05-17 11:16:51 +00:00
|
|
|
|
if ($element_label_class) {
|
2012-12-19 17:10:45 +00:00
|
|
|
|
$attributes['class'][] = $element_label_class;
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
2012-12-19 17:10:45 +00:00
|
|
|
|
$attributes = new Attribute($attributes);
|
2009-05-17 11:16:51 +00:00
|
|
|
|
|
2013-06-10 13:54:59 +00:00
|
|
|
|
$pre = '<' . $object->elementLabelType;
|
2012-12-19 17:10:45 +00:00
|
|
|
|
$pre .= $attributes;
|
2009-05-17 11:16:51 +00:00
|
|
|
|
$pre .= '>';
|
|
|
|
|
|
2013-06-10 13:54:59 +00:00
|
|
|
|
$object->label_html = $pre . $object->label_html . '</' . $object->elementLabelType . '>';
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-13 10:29:57 +00:00
|
|
|
|
$variables['fields'][$id] = $object;
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-25 00:03:24 +00:00
|
|
|
|
/**
|
|
|
|
|
* Returns HTML for multiple views fields.
|
|
|
|
|
*
|
|
|
|
|
* @param $variables
|
|
|
|
|
* An associative array containing:
|
|
|
|
|
* - fields: An array of field objects. Each field object contains:
|
|
|
|
|
* - separator: A string that separates the fields.
|
|
|
|
|
* - wrapper_suffix: A string added to the beginning of the fields.
|
|
|
|
|
* - label_html: An HTML string that labels the fields.
|
|
|
|
|
* - content: The fields.
|
|
|
|
|
* - wrapper_suffix: A string added to the end of the fields.
|
|
|
|
|
*
|
|
|
|
|
* @see template_preprocess_views_view_fields()
|
|
|
|
|
*/
|
|
|
|
|
function theme_views_view_fields($variables) {
|
|
|
|
|
$fields = $variables['fields'];
|
|
|
|
|
$output = '';
|
|
|
|
|
|
2013-08-14 12:21:01 +00:00
|
|
|
|
foreach ($fields as $field) {
|
2013-05-25 00:03:24 +00:00
|
|
|
|
if (!empty($field->separator)) {
|
|
|
|
|
$output .= $field->separator;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$output .= $field->wrapper_prefix;
|
|
|
|
|
$output .= $field->label_html;
|
|
|
|
|
$output .= $field->content;
|
|
|
|
|
|
|
|
|
|
$output .= $field->wrapper_suffix;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $output;
|
|
|
|
|
}
|
|
|
|
|
|
2009-05-17 11:16:51 +00:00
|
|
|
|
/**
|
2013-05-24 17:30:47 +00:00
|
|
|
|
* Prepares variables for views single grouping templates.
|
|
|
|
|
*
|
|
|
|
|
* Default template: views-view-grouping.html.twig.
|
|
|
|
|
*
|
2013-07-13 10:29:57 +00:00
|
|
|
|
* @param array $variables
|
2013-05-24 17:30:47 +00:00
|
|
|
|
* An associative array containing:
|
|
|
|
|
* - view: The view object.
|
|
|
|
|
* - rows: The rows returned from the view.
|
|
|
|
|
* - grouping_level: Integer indicating the hierarchical level of the
|
|
|
|
|
* grouping.
|
|
|
|
|
* - content: The content to be grouped.
|
|
|
|
|
* - title: The group heading.
|
|
|
|
|
*/
|
2013-07-13 10:29:57 +00:00
|
|
|
|
function template_preprocess_views_view_grouping(&$variables) {
|
|
|
|
|
$variables['content'] = $variables['view']->style_plugin->renderGroupingSets($variables['rows'], $variables['grouping_level']);
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Display a single views field.
|
|
|
|
|
*
|
|
|
|
|
* Interesting bits of info:
|
|
|
|
|
* $field->field_alias says what the raw value in $row will be. Reach it like
|
|
|
|
|
* this: @code { $row->{$field->field_alias} @endcode
|
|
|
|
|
*/
|
2013-07-13 10:29:57 +00:00
|
|
|
|
function theme_views_view_field($variables) {
|
|
|
|
|
return $variables['output'];
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2013-05-24 17:35:51 +00:00
|
|
|
|
* Prepares variables for views field templates.
|
2009-05-17 11:16:51 +00:00
|
|
|
|
*
|
2013-05-24 17:35:51 +00:00
|
|
|
|
* Default template: views-view-field.html.twig.
|
|
|
|
|
*
|
2013-07-13 10:29:57 +00:00
|
|
|
|
* @param array $variables
|
2013-05-24 17:35:51 +00:00
|
|
|
|
* An associative array containing:
|
|
|
|
|
* - field: The field handler object for the current field.
|
|
|
|
|
* - row: Object representing the raw result of the SQL query for the current
|
|
|
|
|
* field.
|
|
|
|
|
* - view: Instance of the ViewExecutable object for the parent view.
|
2009-05-17 11:16:51 +00:00
|
|
|
|
*/
|
2013-07-13 10:29:57 +00:00
|
|
|
|
function template_preprocess_views_view_field(&$variables) {
|
|
|
|
|
$variables['output'] = $variables['field']->advancedRender($variables['row']);
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2013-05-24 17:28:53 +00:00
|
|
|
|
* Prepares variables for views summary templates.
|
|
|
|
|
*
|
|
|
|
|
* The summary prints a single record from a row, with fields.
|
|
|
|
|
*
|
|
|
|
|
* Default template: views-view-summary.html.twig.
|
|
|
|
|
*
|
2013-07-13 10:29:57 +00:00
|
|
|
|
* @param array $variables
|
2013-05-24 17:28:53 +00:00
|
|
|
|
* An associative array containing:
|
|
|
|
|
* - view: A ViewExecutable object.
|
|
|
|
|
* - rows: The raw row data.
|
2009-05-17 11:16:51 +00:00
|
|
|
|
*/
|
2013-07-13 10:29:57 +00:00
|
|
|
|
function template_preprocess_views_view_summary(&$variables) {
|
|
|
|
|
$view = $variables['view'];
|
2009-05-17 11:16:51 +00:00
|
|
|
|
$argument = $view->argument[$view->build_info['summary_level']];
|
|
|
|
|
|
|
|
|
|
$url_options = array();
|
|
|
|
|
|
|
|
|
|
if (!empty($view->exposed_raw_input)) {
|
|
|
|
|
$url_options['query'] = $view->exposed_raw_input;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-28 10:43:51 +00:00
|
|
|
|
$active_urls = array(
|
2012-05-15 15:10:47 +00:00
|
|
|
|
url(current_path(), array('alias' => TRUE)), // force system path
|
|
|
|
|
url(current_path()), // could be an alias
|
2014-02-28 10:43:51 +00:00
|
|
|
|
);
|
|
|
|
|
$active_urls = array_combine($active_urls, $active_urls);
|
2009-05-17 11:16:51 +00:00
|
|
|
|
|
2013-05-24 17:28:53 +00:00
|
|
|
|
// Collect all arguments foreach row, to be able to alter them for example
|
|
|
|
|
// by the validator. This is not done per single argument value, because this
|
|
|
|
|
// could cause performance problems.
|
2009-05-17 11:16:51 +00:00
|
|
|
|
$row_args = array();
|
|
|
|
|
|
2013-07-13 10:29:57 +00:00
|
|
|
|
foreach ($variables['rows'] as $id => $row) {
|
2013-06-05 07:22:07 +00:00
|
|
|
|
$row_args[$id] = $argument->summaryArgument($row);
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
2013-06-11 13:47:42 +00:00
|
|
|
|
$argument->processSummaryArguments($row_args);
|
2009-05-17 11:16:51 +00:00
|
|
|
|
|
2013-07-13 10:29:57 +00:00
|
|
|
|
foreach ($variables['rows'] as $id => $row) {
|
2013-07-30 22:28:34 +00:00
|
|
|
|
$variables['rows'][$id]->attributes = array();
|
2013-07-13 10:29:57 +00:00
|
|
|
|
$variables['rows'][$id]->link = $argument->summaryName($row);
|
2009-05-17 11:16:51 +00:00
|
|
|
|
$args = $view->args;
|
|
|
|
|
$args[$argument->position] = $row_args[$id];
|
|
|
|
|
|
|
|
|
|
$base_path = NULL;
|
|
|
|
|
if (!empty($argument->options['summary_options']['base_path'])) {
|
|
|
|
|
$base_path = $argument->options['summary_options']['base_path'];
|
|
|
|
|
}
|
2013-07-13 10:29:57 +00:00
|
|
|
|
$variables['rows'][$id]->url = url($view->getUrl($args, $base_path), $url_options);
|
|
|
|
|
$variables['rows'][$id]->count = intval($row->{$argument->count_alias});
|
|
|
|
|
if (isset($active_urls[$variables['rows'][$id]->url])) {
|
2013-07-30 22:28:34 +00:00
|
|
|
|
$variables['rows'][$id]->attributes['class'][] = 'active';
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
2013-07-30 22:28:34 +00:00
|
|
|
|
$variables['rows'][$id]->attributes = new Attribute($variables['rows'][$id]->attributes);
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2013-05-24 17:34:06 +00:00
|
|
|
|
* Prepares variables for unformatted summary view templates.
|
|
|
|
|
*
|
|
|
|
|
* Default template: views-view-summary-unformatted.html.twig.
|
|
|
|
|
*
|
2013-07-13 10:29:57 +00:00
|
|
|
|
* @param array $variables
|
2013-05-24 17:34:06 +00:00
|
|
|
|
* An associative array containing:
|
|
|
|
|
* - view: A ViewExecutable object.
|
|
|
|
|
* - rows: The raw row data.
|
|
|
|
|
* - options: An array of options. Each option contains:
|
|
|
|
|
* - separator: A string to be placed between inline fields to keep them
|
|
|
|
|
* visually distinct.
|
2009-05-17 11:16:51 +00:00
|
|
|
|
*/
|
2013-07-13 10:29:57 +00:00
|
|
|
|
function template_preprocess_views_view_summary_unformatted(&$variables) {
|
|
|
|
|
$view = $variables['view'];
|
2009-05-17 11:16:51 +00:00
|
|
|
|
$argument = $view->argument[$view->build_info['summary_level']];
|
|
|
|
|
|
|
|
|
|
$url_options = array();
|
|
|
|
|
|
|
|
|
|
if (!empty($view->exposed_raw_input)) {
|
|
|
|
|
$url_options['query'] = $view->exposed_raw_input;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$count = 0;
|
2014-02-28 10:43:51 +00:00
|
|
|
|
$active_urls = array(
|
2013-05-24 17:34:06 +00:00
|
|
|
|
// Force system path.
|
|
|
|
|
url(current_path(), array('alias' => TRUE)),
|
|
|
|
|
// Could be an alias.
|
|
|
|
|
url(current_path()),
|
2014-02-28 10:43:51 +00:00
|
|
|
|
);
|
|
|
|
|
$active_urls = array_combine($active_urls, $active_urls);
|
2009-05-17 11:16:51 +00:00
|
|
|
|
|
2013-05-24 17:34:06 +00:00
|
|
|
|
// Collect all arguments for each row, to be able to alter them for example
|
|
|
|
|
// by the validator. This is not done per single argument value, because
|
|
|
|
|
// this could cause performance problems.
|
2009-05-17 11:16:51 +00:00
|
|
|
|
$row_args = array();
|
2013-07-13 10:29:57 +00:00
|
|
|
|
foreach ($variables['rows'] as $id => $row) {
|
2013-06-05 07:22:07 +00:00
|
|
|
|
$row_args[$id] = $argument->summaryArgument($row);
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
2013-06-11 13:47:42 +00:00
|
|
|
|
$argument->processSummaryArguments($row_args);
|
2009-05-17 11:16:51 +00:00
|
|
|
|
|
2013-07-13 10:29:57 +00:00
|
|
|
|
foreach ($variables['rows'] as $id => $row) {
|
2013-05-24 17:34:06 +00:00
|
|
|
|
// Only false on first time.
|
2009-05-17 11:16:51 +00:00
|
|
|
|
if ($count++) {
|
2013-07-13 10:29:57 +00:00
|
|
|
|
$variables['rows'][$id]->separator = filter_xss_admin($variables['options']['separator']);
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
2013-07-30 22:28:34 +00:00
|
|
|
|
$variables['rows'][$id]->attributes = array();
|
2013-07-13 10:29:57 +00:00
|
|
|
|
$variables['rows'][$id]->link = $argument->summaryName($row);
|
2009-05-17 11:16:51 +00:00
|
|
|
|
$args = $view->args;
|
|
|
|
|
$args[$argument->position] = $row_args[$id];
|
|
|
|
|
|
|
|
|
|
$base_path = NULL;
|
|
|
|
|
if (!empty($argument->options['summary_options']['base_path'])) {
|
|
|
|
|
$base_path = $argument->options['summary_options']['base_path'];
|
|
|
|
|
}
|
2013-07-13 10:29:57 +00:00
|
|
|
|
$variables['rows'][$id]->url = url($view->getUrl($args, $base_path), $url_options);
|
|
|
|
|
$variables['rows'][$id]->count = intval($row->{$argument->count_alias});
|
|
|
|
|
if (isset($active_urls[$variables['rows'][$id]->url])) {
|
2013-07-30 22:28:34 +00:00
|
|
|
|
$variables['rows'][$id]->attributes['class'][] = 'active';
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
2013-07-30 22:28:34 +00:00
|
|
|
|
$variables['rows'][$id]->attributes = new Attribute($variables['rows'][$id]->attributes);
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2013-05-24 17:24:22 +00:00
|
|
|
|
* Prepares variables for views table templates.
|
|
|
|
|
*
|
|
|
|
|
* Default template: views-view-table.html.twig.
|
|
|
|
|
*
|
2013-07-13 10:29:57 +00:00
|
|
|
|
* @param array $variables
|
2013-05-24 17:24:22 +00:00
|
|
|
|
* An associative array containing:
|
|
|
|
|
* - view: A ViewExecutable object.
|
|
|
|
|
* - rows: The raw row data.
|
2009-05-17 11:16:51 +00:00
|
|
|
|
*/
|
2013-07-13 10:29:57 +00:00
|
|
|
|
function template_preprocess_views_view_table(&$variables) {
|
|
|
|
|
$view = $variables['view'];
|
2009-05-17 11:16:51 +00:00
|
|
|
|
|
2013-05-24 17:24:22 +00:00
|
|
|
|
// We need the raw data for this grouping, which is passed in
|
2013-07-13 10:29:57 +00:00
|
|
|
|
// as $variables['rows'].
|
2009-05-17 11:16:51 +00:00
|
|
|
|
// However, the template also needs to use for the rendered fields. We
|
2013-07-13 10:29:57 +00:00
|
|
|
|
// therefore swap the raw data out to a new variable and reset $variables['rows']
|
2009-05-17 11:16:51 +00:00
|
|
|
|
// so that it can get rebuilt.
|
|
|
|
|
// Store rows so that they may be used by further preprocess functions.
|
2013-07-13 10:29:57 +00:00
|
|
|
|
$result = $variables['result'] = $variables['rows'];
|
|
|
|
|
$variables['rows'] = array();
|
|
|
|
|
$variables['header'] = array();
|
2009-05-17 11:16:51 +00:00
|
|
|
|
|
2013-05-24 17:24:22 +00:00
|
|
|
|
$options = $view->style_plugin->options;
|
|
|
|
|
$handler = $view->style_plugin;
|
2009-05-17 11:16:51 +00:00
|
|
|
|
|
|
|
|
|
$row_class_special = isset($options['row_class_special']) ? $options['row_class_special'] : TRUE;
|
|
|
|
|
|
2013-05-24 17:24:22 +00:00
|
|
|
|
$fields = &$view->field;
|
2013-06-05 06:48:07 +00:00
|
|
|
|
$columns = $handler->sanitizeColumns($options['columns'], $fields);
|
2009-05-17 11:16:51 +00:00
|
|
|
|
|
2013-05-24 17:24:22 +00:00
|
|
|
|
$active = !empty($handler->active) ? $handler->active : '';
|
|
|
|
|
$order = !empty($handler->order) ? $handler->order : 'asc';
|
2009-05-17 11:16:51 +00:00
|
|
|
|
|
2012-10-06 23:52:06 +00:00
|
|
|
|
// A boolean variable which stores whether the table has a responsive class.
|
|
|
|
|
$responsive = FALSE;
|
|
|
|
|
|
2013-05-24 17:24:22 +00:00
|
|
|
|
$query = tablesort_get_query_parameters();
|
2009-05-17 11:16:51 +00:00
|
|
|
|
if (isset($view->exposed_raw_input)) {
|
|
|
|
|
$query += $view->exposed_raw_input;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-30 22:28:34 +00:00
|
|
|
|
// A boolean to store whether the table's header has any labels.
|
|
|
|
|
$has_header_labels = FALSE;
|
2009-05-17 11:16:51 +00:00
|
|
|
|
foreach ($columns as $field => $column) {
|
2013-05-24 17:24:22 +00:00
|
|
|
|
// Create a second variable so we can easily find what fields we have and
|
|
|
|
|
// what the CSS classes should be.
|
2013-07-13 10:29:57 +00:00
|
|
|
|
$variables['fields'][$field] = drupal_clean_css_identifier($field);
|
2009-05-17 11:16:51 +00:00
|
|
|
|
if ($active == $field) {
|
2013-07-13 10:29:57 +00:00
|
|
|
|
$variables['fields'][$field] .= ' active';
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-30 22:28:34 +00:00
|
|
|
|
// Render the header labels.
|
2009-05-17 11:16:51 +00:00
|
|
|
|
if ($field == $column && empty($fields[$field]->options['exclude'])) {
|
2014-02-13 11:53:32 +00:00
|
|
|
|
$label = String::checkPlain(!empty($fields[$field]) ? $fields[$field]->label() : '');
|
2013-06-13 08:25:45 +00:00
|
|
|
|
if (empty($options['info'][$field]['sortable']) || !$fields[$field]->clickSortable()) {
|
2013-07-30 22:28:34 +00:00
|
|
|
|
$variables['header'][$field]['content'] = $label;
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$initial = !empty($options['info'][$field]['default_sort_order']) ? $options['info'][$field]['default_sort_order'] : 'asc';
|
|
|
|
|
|
|
|
|
|
if ($active == $field) {
|
|
|
|
|
$initial = ($order == 'asc') ? 'desc' : 'asc';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$title = t('sort by @s', array('@s' => $label));
|
|
|
|
|
if ($active == $field) {
|
2013-06-09 20:45:55 +00:00
|
|
|
|
$tablesort_indicator = array(
|
|
|
|
|
'#theme' => 'tablesort_indicator',
|
|
|
|
|
'#style' => $initial,
|
|
|
|
|
);
|
|
|
|
|
$label .= drupal_render($tablesort_indicator);
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$query['order'] = $field;
|
|
|
|
|
$query['sort'] = $initial;
|
|
|
|
|
$link_options = array(
|
|
|
|
|
'html' => TRUE,
|
|
|
|
|
'attributes' => array('title' => $title),
|
|
|
|
|
'query' => $query,
|
|
|
|
|
);
|
2013-07-30 22:28:34 +00:00
|
|
|
|
$variables['header'][$field]['content'] = l($label, current_path(), $link_options);
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Set up the header label class.
|
2013-07-30 22:28:34 +00:00
|
|
|
|
$variables['header'][$field]['attributes'] = array();
|
2009-05-17 11:16:51 +00:00
|
|
|
|
if ($fields[$field]->options['element_default_classes']) {
|
2013-07-30 22:28:34 +00:00
|
|
|
|
$variables['header'][$field]['attributes']['class'][] = 'views-field';
|
|
|
|
|
$variables['header'][$field]['attributes']['class'][] = 'views-field-' . $variables['fields'][$field];
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
2013-05-29 13:27:16 +00:00
|
|
|
|
$class = $fields[$field]->elementLabelClasses(0);
|
2009-05-17 11:16:51 +00:00
|
|
|
|
if ($class) {
|
2013-07-30 22:28:34 +00:00
|
|
|
|
$variables['header'][$field]['attributes']['class'][] = $class;
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
2012-10-06 23:52:06 +00:00
|
|
|
|
// Add responsive header classes.
|
|
|
|
|
if (!empty($options['info'][$field]['responsive'])) {
|
2013-07-30 22:28:34 +00:00
|
|
|
|
$variables['header'][$field]['attributes']['class'][] = $options['info'][$field]['responsive'];
|
2012-10-06 23:52:06 +00:00
|
|
|
|
$responsive = TRUE;
|
|
|
|
|
}
|
2013-05-24 17:24:22 +00:00
|
|
|
|
// Add a CSS align class to each field if one was set.
|
2009-05-17 11:16:51 +00:00
|
|
|
|
if (!empty($options['info'][$field]['align'])) {
|
2013-07-30 22:28:34 +00:00
|
|
|
|
$variables['header'][$field]['attributes']['class'][] = drupal_clean_css_identifier($options['info'][$field]['align']);
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
|
|
|
|
// Add a header label wrapper if one was selected.
|
2013-07-30 22:28:34 +00:00
|
|
|
|
if ($variables['header'][$field]['content']) {
|
2013-06-10 13:54:59 +00:00
|
|
|
|
$element_label_type = $fields[$field]->elementLabelType(TRUE, TRUE);
|
2009-05-17 11:16:51 +00:00
|
|
|
|
if ($element_label_type) {
|
2013-07-30 22:28:34 +00:00
|
|
|
|
$variables['header'][$field]['content'] = '<' . $element_label_type . '>' . $variables['header'][$field]['content'] . '</' . $element_label_type . '>';
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
2013-07-24 20:30:21 +00:00
|
|
|
|
// Improves accessibility of complex tables.
|
2013-07-30 22:28:34 +00:00
|
|
|
|
$variables['header'][$field]['attributes']['id'] = drupal_html_id('view-' . $field . '-table-column');
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
2013-07-30 22:28:34 +00:00
|
|
|
|
// Check if header label is not empty.
|
|
|
|
|
if (!empty($variables['header'][$field]['content'])) {
|
|
|
|
|
$has_header_labels = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$variables['header'][$field]['attributes'] = new Attribute($variables['header'][$field]['attributes']);
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-24 17:24:22 +00:00
|
|
|
|
// Add a CSS align class to each field if one was set.
|
2009-05-17 11:16:51 +00:00
|
|
|
|
if (!empty($options['info'][$field]['align'])) {
|
2013-07-13 10:29:57 +00:00
|
|
|
|
$variables['fields'][$field] .= ' ' . drupal_clean_css_identifier($options['info'][$field]['align']);
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Render each field into its appropriate column.
|
|
|
|
|
foreach ($result as $num => $row) {
|
2013-08-06 05:34:34 +00:00
|
|
|
|
|
|
|
|
|
// Skip building the attributes and content if the field is to be excluded
|
|
|
|
|
// from the display.
|
|
|
|
|
if (!empty($fields[$field]->options['exclude'])) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Reference to the column in the loop to make the code easier to read.
|
|
|
|
|
$column_reference =& $variables['rows'][$num]['columns'][$column];
|
|
|
|
|
|
2013-05-24 17:24:22 +00:00
|
|
|
|
// Add field classes.
|
2013-08-06 05:34:34 +00:00
|
|
|
|
$column_reference['attributes'] = array();
|
2009-05-17 11:16:51 +00:00
|
|
|
|
if ($fields[$field]->options['element_default_classes']) {
|
2013-08-06 05:34:34 +00:00
|
|
|
|
$column_reference['attributes']['class'][] = 'views-field';
|
|
|
|
|
$column_reference['attributes']['class'][] = 'views-field-' . $variables['fields'][$field];
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-13 08:12:00 +00:00
|
|
|
|
if ($classes = $fields[$field]->elementClasses($num)) {
|
2013-08-06 05:34:34 +00:00
|
|
|
|
$column_reference['attributes']['class'][] = $classes;
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
2013-08-06 05:34:34 +00:00
|
|
|
|
|
2012-10-06 23:52:06 +00:00
|
|
|
|
// Add responsive header classes.
|
|
|
|
|
if (!empty($options['info'][$field]['responsive'])) {
|
2013-08-06 05:34:34 +00:00
|
|
|
|
$column_reference['attributes']['class'][] = $options['info'][$field]['responsive'];
|
2012-10-06 23:52:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-24 20:30:21 +00:00
|
|
|
|
// Improves accessibility of complex tables.
|
2013-07-30 22:28:34 +00:00
|
|
|
|
if (isset($variables['header'][$field]['attributes']['id'])) {
|
2013-08-06 05:34:34 +00:00
|
|
|
|
$column_reference['attributes']['headers'] = array($variables['header'][$field]['attributes']['id']);
|
2013-07-24 20:30:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-08-06 05:34:34 +00:00
|
|
|
|
if (!empty($fields[$field])) {
|
2013-06-11 22:33:23 +00:00
|
|
|
|
$field_output = $handler->getField($num, $field);
|
2013-05-29 23:56:43 +00:00
|
|
|
|
$element_type = $fields[$field]->elementType(TRUE, TRUE);
|
2009-05-17 11:16:51 +00:00
|
|
|
|
if ($element_type) {
|
|
|
|
|
$field_output = '<' . $element_type . '>' . $field_output . '</' . $element_type . '>';
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-30 22:28:34 +00:00
|
|
|
|
// Only bother with separators and stuff if the field shows up.
|
2013-08-06 05:34:34 +00:00
|
|
|
|
if (!empty($field_output) && empty($column_reference['content'])) {
|
2013-07-30 22:28:34 +00:00
|
|
|
|
// Place the field into the column, along with an optional separator.
|
2013-08-06 05:34:34 +00:00
|
|
|
|
if (!empty($column_reference['content'])) {
|
2013-07-30 22:28:34 +00:00
|
|
|
|
if (!empty($options['info'][$column]['separator'])) {
|
2013-08-06 05:34:34 +00:00
|
|
|
|
$column_reference['content'] .= filter_xss_admin($options['info'][$column]['separator']);
|
2013-07-30 22:28:34 +00:00
|
|
|
|
}
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
2013-07-30 22:28:34 +00:00
|
|
|
|
else {
|
2013-08-06 05:34:34 +00:00
|
|
|
|
$column_reference['content'] = '';
|
2013-07-30 22:28:34 +00:00
|
|
|
|
}
|
2013-08-06 05:34:34 +00:00
|
|
|
|
$column_reference['content'] .= $field_output;
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-08-06 05:34:34 +00:00
|
|
|
|
$column_reference['attributes'] = new Attribute($column_reference['attributes']);
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-24 17:24:22 +00:00
|
|
|
|
// Remove columns if the option is hide empty column is checked and the
|
|
|
|
|
// field is not empty.
|
2009-05-17 11:16:51 +00:00
|
|
|
|
if (!empty($options['info'][$field]['empty_column'])) {
|
|
|
|
|
$empty = TRUE;
|
2013-08-14 12:21:01 +00:00
|
|
|
|
foreach ($variables['rows'] as $columns) {
|
2009-05-17 11:16:51 +00:00
|
|
|
|
$empty &= empty($columns[$column]);
|
|
|
|
|
}
|
|
|
|
|
if ($empty) {
|
2013-08-14 12:21:01 +00:00
|
|
|
|
foreach ($variables['rows'] as &$column_items) {
|
2009-05-17 11:16:51 +00:00
|
|
|
|
unset($column_items[$column]);
|
2013-07-13 10:29:57 +00:00
|
|
|
|
unset($variables['header'][$column]);
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Hide table header if all labels are empty.
|
2013-07-30 22:28:34 +00:00
|
|
|
|
if (!$has_header_labels) {
|
2013-07-13 10:29:57 +00:00
|
|
|
|
$variables['header'] = array();
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$count = 0;
|
2013-07-13 10:29:57 +00:00
|
|
|
|
foreach ($variables['rows'] as $num => $row) {
|
2013-07-30 22:28:34 +00:00
|
|
|
|
$variables['rows'][$num]['attributes'] = array();
|
2009-05-17 11:16:51 +00:00
|
|
|
|
if ($row_class_special) {
|
2013-07-30 22:28:34 +00:00
|
|
|
|
$variables['rows'][$num]['attributes']['class'][] = ($count++ % 2 == 0) ? 'odd' : 'even';
|
2012-12-19 17:10:45 +00:00
|
|
|
|
if ($num === 0) {
|
2013-07-30 22:28:34 +00:00
|
|
|
|
$variables['rows'][$num]['attributes']['class'][] = 'views-row-first';
|
2012-12-19 17:10:45 +00:00
|
|
|
|
}
|
2013-07-13 10:29:57 +00:00
|
|
|
|
elseif ($num === (count($variables['rows']) - 1)) {
|
2013-07-30 22:28:34 +00:00
|
|
|
|
$variables['rows'][$num]['attributes']['class'][] = 'views-row-last';
|
2012-12-19 17:10:45 +00:00
|
|
|
|
}
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
2013-05-28 20:59:28 +00:00
|
|
|
|
if ($row_class = $handler->getRowClass($num)) {
|
2013-07-30 22:28:34 +00:00
|
|
|
|
$variables['rows'][$num]['attributes']['class'][] = $row_class;
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
2013-07-30 22:28:34 +00:00
|
|
|
|
$variables['rows'][$num]['attributes'] = new Attribute($variables['rows'][$num]['attributes']);
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-13 10:29:57 +00:00
|
|
|
|
$variables['attributes']['class'][] = 'views-table';
|
|
|
|
|
$variables['attributes']['class'][] = 'views-view-table';
|
|
|
|
|
if (empty($variables['rows']) && !empty($options['empty_table'])) {
|
2013-04-26 09:33:29 +00:00
|
|
|
|
$build = $view->display_handler->renderArea('empty');
|
2013-07-30 22:28:34 +00:00
|
|
|
|
$variables['rows'][0]['columns'][0]['content'] = drupal_render($build);
|
|
|
|
|
$variables['rows'][0]['attributes'] = new Attribute(array('class' => 'odd'));
|
2009-05-17 11:16:51 +00:00
|
|
|
|
// Calculate the amounts of rows with output.
|
2013-07-30 22:28:34 +00:00
|
|
|
|
$variables['rows'][0]['columns'][0]['attributes'] = new Attribute(array(
|
2013-07-13 10:29:57 +00:00
|
|
|
|
'colspan' => count($variables['header']),
|
2012-12-19 17:10:45 +00:00
|
|
|
|
'class' => 'views-empty',
|
|
|
|
|
));
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!empty($options['sticky'])) {
|
Issue #1996238 by sun, nod_, damiankloip, Wim Leers, longwave, alexpott, Xano, mdrummond, Mark Carver, Jeff Burnz, highrockmedia, joelpittet, et al: Replace hook_library_info() by *.libraries.yml file.
2014-02-23 04:56:51 +00:00
|
|
|
|
$variables['view']->element['#attached']['library'][] = array('core', 'drupal.tableheader');
|
2013-07-13 10:29:57 +00:00
|
|
|
|
$variables['attributes']['class'][] = "sticky-enabled";
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
2013-07-13 10:29:57 +00:00
|
|
|
|
$variables['attributes']['class'][] = 'cols-' . count($variables['header']);
|
2009-05-17 11:16:51 +00:00
|
|
|
|
|
2013-06-15 07:19:01 +00:00
|
|
|
|
// Add the caption to the list if set.
|
|
|
|
|
if (!empty($handler->options['caption'])) {
|
2013-07-13 10:29:57 +00:00
|
|
|
|
$variables['caption'] = Xss::filterAdmin($handler->options['caption']);
|
|
|
|
|
$variables['caption_needed'] = TRUE;
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
2013-06-15 07:19:01 +00:00
|
|
|
|
else {
|
2013-07-13 10:29:57 +00:00
|
|
|
|
$variables['caption'] = '';
|
|
|
|
|
$variables['caption_needed'] = FALSE;
|
2013-06-15 07:19:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-13 10:29:57 +00:00
|
|
|
|
$variables['summary'] = $handler->options['summary'];
|
|
|
|
|
$variables['description'] = $handler->options['description'];
|
|
|
|
|
$variables['caption_needed'] |= !empty($variables['summary']) || !empty($variables['description']);
|
2013-06-15 07:19:01 +00:00
|
|
|
|
|
2012-10-06 23:52:06 +00:00
|
|
|
|
// If the table has headers and it should react responsively to columns hidden
|
|
|
|
|
// with the classes represented by the constants RESPONSIVE_PRIORITY_MEDIUM
|
|
|
|
|
// and RESPONSIVE_PRIORITY_LOW, add the tableresponsive behaviors.
|
2013-07-13 10:29:57 +00:00
|
|
|
|
if (isset($variables['header']) && $responsive) {
|
Issue #1996238 by sun, nod_, damiankloip, Wim Leers, longwave, alexpott, Xano, mdrummond, Mark Carver, Jeff Burnz, highrockmedia, joelpittet, et al: Replace hook_library_info() by *.libraries.yml file.
2014-02-23 04:56:51 +00:00
|
|
|
|
$variables['view']->element['#attached']['library'][] = array('core', 'drupal.tableresponsive');
|
2012-10-06 23:52:06 +00:00
|
|
|
|
// Add 'responsive-enabled' class to the table to identify it for JS.
|
|
|
|
|
// This is needed to target tables constructed by this function.
|
2013-07-13 10:29:57 +00:00
|
|
|
|
$variables['attributes']['class'][] = 'responsive-enabled';
|
2012-10-06 23:52:06 +00:00
|
|
|
|
}
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2013-05-24 17:27:49 +00:00
|
|
|
|
* Prepares variables for views grid style templates.
|
|
|
|
|
*
|
|
|
|
|
* Default template: views-view-grid.html.twig.
|
|
|
|
|
*
|
2013-07-13 10:29:57 +00:00
|
|
|
|
* @param array $variables
|
2013-05-24 17:27:49 +00:00
|
|
|
|
* An associative array containing:
|
|
|
|
|
* - view: The view object.
|
|
|
|
|
* - rows: An array of row items. Each row is an array of content.
|
2009-05-17 11:16:51 +00:00
|
|
|
|
*/
|
2013-07-13 10:29:57 +00:00
|
|
|
|
function template_preprocess_views_view_grid(&$variables) {
|
2013-07-16 06:37:55 +00:00
|
|
|
|
$options = $variables['options'] = $variables['view']->style_plugin->options;
|
|
|
|
|
$horizontal = ($options['alignment'] === 'horizontal');
|
|
|
|
|
|
|
|
|
|
$variables['attributes']['class'] = array(
|
|
|
|
|
'views-view-grid',
|
|
|
|
|
$options['alignment'],
|
|
|
|
|
'cols-' . $options['columns'],
|
|
|
|
|
'clearfix',
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$col = 0;
|
|
|
|
|
$row = 0;
|
|
|
|
|
$items = array();
|
|
|
|
|
$remainders = count($variables['rows']) % $options['columns'];
|
|
|
|
|
$num_rows = floor(count($variables['rows']) / $options['columns']);
|
|
|
|
|
|
|
|
|
|
// Iterate over each rendered views result row.
|
2013-07-26 16:42:05 +00:00
|
|
|
|
foreach ($variables['rows'] as $result_index => $item) {
|
2013-07-16 06:37:55 +00:00
|
|
|
|
|
|
|
|
|
// Add the item.
|
|
|
|
|
if ($horizontal) {
|
|
|
|
|
$items[$row]['content'][$col]['content'] = $item;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$items[$col]['content'][$row]['content'] = $item;
|
|
|
|
|
}
|
2009-05-17 11:16:51 +00:00
|
|
|
|
|
2013-07-16 06:37:55 +00:00
|
|
|
|
// Create attributes for rows.
|
|
|
|
|
if (!$horizontal || ($horizontal && empty($items[$row]['attributes']))) {
|
|
|
|
|
$row_attributes = array('class' => array());
|
|
|
|
|
// Add default views row classes.
|
|
|
|
|
if ($options['row_class_default']) {
|
|
|
|
|
$row_attributes['class'][] = 'views-row';
|
|
|
|
|
$row_attributes['class'][] = 'row-' . ($row + 1);
|
|
|
|
|
if ($horizontal) {
|
|
|
|
|
$row_attributes['class'][] = 'clearfix';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Add custom row classes.
|
2013-07-26 16:42:05 +00:00
|
|
|
|
$row_class = array_filter(explode(' ', $variables['view']->style_plugin->getCustomClass($result_index, 'row')));
|
2013-07-16 06:37:55 +00:00
|
|
|
|
if (!empty($row_class)) {
|
|
|
|
|
$row_attributes['class'] = array_merge($row_attributes['class'], $row_class);
|
|
|
|
|
}
|
|
|
|
|
// Add row attributes to the item.
|
|
|
|
|
if ($horizontal) {
|
|
|
|
|
$items[$row]['attributes'] = new Attribute($row_attributes);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$items[$col]['content'][$row]['attributes'] = new Attribute($row_attributes);
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-07-16 06:37:55 +00:00
|
|
|
|
|
|
|
|
|
// Create attributes for columns.
|
|
|
|
|
if ($horizontal || (!$horizontal && empty($items[$col]['attributes']))) {
|
|
|
|
|
$col_attributes = array('class' => array());
|
|
|
|
|
// Add default views column classes.
|
|
|
|
|
if ($options['col_class_default']) {
|
|
|
|
|
$col_attributes['class'][] = 'views-col';
|
|
|
|
|
$col_attributes['class'][] = 'col-' . ($col + 1);
|
|
|
|
|
if (!$horizontal) {
|
|
|
|
|
$col_attributes['class'][] = 'clearfix';
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-07-16 06:37:55 +00:00
|
|
|
|
// Add custom column classes.
|
2013-07-26 16:42:05 +00:00
|
|
|
|
$col_class = array_filter(explode(' ', $variables['view']->style_plugin->getCustomClass($result_index, 'col')));
|
2013-07-16 06:37:55 +00:00
|
|
|
|
if (!empty($col_class)) {
|
|
|
|
|
$col_attributes['class'] = array_merge($col_attributes['class'], $col_class);
|
|
|
|
|
}
|
|
|
|
|
// Add automatic width for columns.
|
|
|
|
|
if ($options['automatic_width']) {
|
|
|
|
|
$col_attributes['style'] = 'width: ' . (100 / $options['columns']) . '%;';
|
|
|
|
|
}
|
|
|
|
|
// Add column attributes to the item.
|
|
|
|
|
if ($horizontal) {
|
|
|
|
|
$items[$row]['content'][$col]['attributes'] = new Attribute($col_attributes);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$items[$col]['attributes'] = new Attribute($col_attributes);
|
|
|
|
|
}
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-16 06:37:55 +00:00
|
|
|
|
// Increase, decrease or reset appropriate integers.
|
|
|
|
|
if ($horizontal) {
|
|
|
|
|
if ($col == 0 && $col != ($options['columns'] - 1)) {
|
|
|
|
|
$col++;
|
|
|
|
|
}
|
|
|
|
|
elseif ($col >= ($options['columns'] - 1)) {
|
|
|
|
|
$col = 0;
|
|
|
|
|
$row++;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$col++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$row++;
|
2009-05-17 11:16:51 +00:00
|
|
|
|
if (!$remainders && $row == $num_rows) {
|
|
|
|
|
$row = 0;
|
|
|
|
|
$col++;
|
|
|
|
|
}
|
|
|
|
|
elseif ($remainders && $row == $num_rows + 1) {
|
|
|
|
|
$row = 0;
|
|
|
|
|
$col++;
|
|
|
|
|
$remainders--;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-16 06:37:55 +00:00
|
|
|
|
// Add items to the variables array.
|
|
|
|
|
$variables['items'] = $items;
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2013-05-24 17:25:24 +00:00
|
|
|
|
* Prepares variables for views unformatted rows templates.
|
|
|
|
|
*
|
|
|
|
|
* Default template: views-view-unformatted.html.twig.
|
|
|
|
|
*
|
2013-07-13 10:29:57 +00:00
|
|
|
|
* @param array $variables
|
2013-05-24 17:25:24 +00:00
|
|
|
|
* An associative array containing:
|
|
|
|
|
* - view: The view object.
|
|
|
|
|
* - rows: An array of row items. Each row is an array of content.
|
2009-05-17 11:16:51 +00:00
|
|
|
|
*/
|
2013-07-13 10:29:57 +00:00
|
|
|
|
function template_preprocess_views_view_unformatted(&$variables) {
|
|
|
|
|
$view = $variables['view'];
|
|
|
|
|
$rows = $variables['rows'];
|
2009-05-17 11:16:51 +00:00
|
|
|
|
$style = $view->style_plugin;
|
|
|
|
|
$options = $style->options;
|
|
|
|
|
|
|
|
|
|
$default_row_class = isset($options['default_row_class']) ? $options['default_row_class'] : FALSE;
|
|
|
|
|
$row_class_special = isset($options['row_class_special']) ? $options['row_class_special'] : FALSE;
|
|
|
|
|
// Set up striping values.
|
|
|
|
|
$count = 0;
|
|
|
|
|
$max = count($rows);
|
|
|
|
|
foreach ($rows as $id => $row) {
|
2013-07-30 22:28:34 +00:00
|
|
|
|
$variables['rows'][$id] = array();
|
|
|
|
|
$variables['rows'][$id]['content'] = $row;
|
|
|
|
|
$variables['rows'][$id]['attributes'] = array();
|
2009-05-17 11:16:51 +00:00
|
|
|
|
$count++;
|
|
|
|
|
if ($default_row_class) {
|
2013-07-30 22:28:34 +00:00
|
|
|
|
$variables['rows'][$id]['attributes']['class'][] = 'views-row';
|
|
|
|
|
$variables['rows'][$id]['attributes']['class'][] = 'views-row-' . $count;
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
|
|
|
|
if ($row_class_special) {
|
2013-07-30 22:28:34 +00:00
|
|
|
|
$variables['rows'][$id]['attributes']['class'][] = 'views-row-' . ($count % 2 ? 'odd' : 'even');
|
2009-05-17 11:16:51 +00:00
|
|
|
|
if ($count == 1) {
|
2013-07-30 22:28:34 +00:00
|
|
|
|
$variables['rows'][$id]['attributes']['class'][] = 'views-row-first';
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
|
|
|
|
if ($count == $max) {
|
2013-07-30 22:28:34 +00:00
|
|
|
|
$variables['rows'][$id]['attributes']['class'][] = 'views-row-last';
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-05-28 20:59:28 +00:00
|
|
|
|
if ($row_class = $view->style_plugin->getRowClass($id)) {
|
2013-07-30 22:28:34 +00:00
|
|
|
|
$variables['rows'][$id]['attributes']['class'][] = $row_class;
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
2013-07-30 22:28:34 +00:00
|
|
|
|
$variables['rows'][$id]['attributes'] = new Attribute($variables['rows'][$id]['attributes']);
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2013-05-24 17:26:35 +00:00
|
|
|
|
* Prepares variables for Views HTML list templates.
|
|
|
|
|
*
|
|
|
|
|
* Default template: views-view-list.html.twig.
|
|
|
|
|
*
|
|
|
|
|
* @param array $variables
|
|
|
|
|
* An associative array containing:
|
|
|
|
|
* - view: A View object.
|
2009-05-17 11:16:51 +00:00
|
|
|
|
*/
|
2013-05-24 17:26:35 +00:00
|
|
|
|
function template_preprocess_views_view_list(&$variables) {
|
|
|
|
|
$handler = $variables['view']->style_plugin;
|
2009-05-17 11:16:51 +00:00
|
|
|
|
|
2012-12-19 17:10:45 +00:00
|
|
|
|
// Fetch classes from handler options.
|
2009-05-17 11:16:51 +00:00
|
|
|
|
$class = explode(' ', $handler->options['class']);
|
2012-09-08 18:24:31 +00:00
|
|
|
|
$class = array_map('drupal_clean_css_identifier', $class);
|
2009-05-17 11:16:51 +00:00
|
|
|
|
|
2012-12-19 17:10:45 +00:00
|
|
|
|
// Fetch wrapper classes from handler options.
|
2009-05-17 11:16:51 +00:00
|
|
|
|
$wrapper_class = explode(' ', $handler->options['wrapper_class']);
|
2012-09-08 18:24:31 +00:00
|
|
|
|
$wrapper_class = array_map('drupal_clean_css_identifier', $wrapper_class);
|
2009-05-17 11:16:51 +00:00
|
|
|
|
|
2012-12-19 17:10:45 +00:00
|
|
|
|
// Initialize a new attribute class for $wrapper_class.
|
|
|
|
|
if ($wrapper_class) {
|
2013-07-30 22:28:34 +00:00
|
|
|
|
$variables['attributes']['class'] = $wrapper_class;
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-24 17:26:35 +00:00
|
|
|
|
// Initialize a new attribute class for $class.
|
|
|
|
|
$variables['list']['attributes'] = new Attribute(array('class' => $class));
|
|
|
|
|
$variables['list']['type'] = $handler->options['type'];
|
2012-12-19 17:10:45 +00:00
|
|
|
|
|
2013-05-24 17:26:35 +00:00
|
|
|
|
template_preprocess_views_view_unformatted($variables);
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2013-05-24 17:22:36 +00:00
|
|
|
|
* Prepares variables for RSS feed templates.
|
|
|
|
|
*
|
|
|
|
|
* Default template: views-view-rss.html.twig.
|
|
|
|
|
*
|
2013-07-13 10:29:57 +00:00
|
|
|
|
* @param array $variables
|
2013-05-24 17:22:36 +00:00
|
|
|
|
* An associative array containing:
|
|
|
|
|
* - view: A ViewExecutable object.
|
|
|
|
|
* - rows: The raw row data.
|
2013-11-11 18:59:24 +00:00
|
|
|
|
*/
|
2013-07-13 10:29:57 +00:00
|
|
|
|
function template_preprocess_views_view_rss(&$variables) {
|
2013-11-11 18:59:24 +00:00
|
|
|
|
$view = $variables['view'];
|
2013-07-13 10:29:57 +00:00
|
|
|
|
$items = $variables['rows'];
|
2013-05-24 17:22:36 +00:00
|
|
|
|
$style = $view->style_plugin;
|
2009-05-17 11:16:51 +00:00
|
|
|
|
|
2013-09-16 03:58:06 +00:00
|
|
|
|
$config = \Drupal::config('system.site');
|
2012-08-11 20:02:21 +00:00
|
|
|
|
|
2009-05-17 11:16:51 +00:00
|
|
|
|
// The RSS 2.0 "spec" doesn't indicate HTML can be used in the description.
|
|
|
|
|
// We strip all HTML tags, but need to prevent double encoding from properly
|
|
|
|
|
// escaped source data (such as & becoming &amp;).
|
2014-02-13 11:53:32 +00:00
|
|
|
|
$variables['description'] = String::checkPlain(decode_entities(strip_tags($style->getDescription())));
|
2009-05-17 11:16:51 +00:00
|
|
|
|
|
2012-08-30 09:23:13 +00:00
|
|
|
|
if ($view->display_handler->getOption('sitename_title')) {
|
2013-02-09 00:58:36 +00:00
|
|
|
|
$title = $config->get('name');
|
2012-08-11 20:02:21 +00:00
|
|
|
|
if ($slogan = $config->get('slogan')) {
|
2009-05-17 11:16:51 +00:00
|
|
|
|
$title .= ' - ' . $slogan;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
2012-08-29 19:36:52 +00:00
|
|
|
|
$title = $view->getTitle();
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
2014-02-13 11:53:32 +00:00
|
|
|
|
$variables['title'] = String::checkPlain($title);
|
2009-05-17 11:16:51 +00:00
|
|
|
|
|
2013-05-24 17:22:36 +00:00
|
|
|
|
// Figure out which display which has a path we're using for this feed. If
|
|
|
|
|
// there isn't one, use the global $base_url
|
2012-08-30 09:23:13 +00:00
|
|
|
|
$link_display_id = $view->display_handler->getLinkDisplay();
|
2013-01-15 16:34:32 +00:00
|
|
|
|
if ($link_display_id && $display = $view->displayHandlers->get($link_display_id)) {
|
|
|
|
|
$path = $view->displayHandlers->get($link_display_id)->getPath();
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($path) {
|
2012-08-29 19:36:52 +00:00
|
|
|
|
$path = $view->getUrl(NULL, $path);
|
2009-05-17 11:16:51 +00:00
|
|
|
|
$url_options = array('absolute' => TRUE);
|
|
|
|
|
if (!empty($view->exposed_raw_input)) {
|
|
|
|
|
$url_options['query'] = $view->exposed_raw_input;
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-24 17:22:36 +00:00
|
|
|
|
// Compare the link to the default home page; if it's the default home page,
|
|
|
|
|
// just use $base_url.
|
2012-08-11 20:02:21 +00:00
|
|
|
|
if ($path == $config->get('page.front')) {
|
2009-05-17 11:16:51 +00:00
|
|
|
|
$path = '';
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-13 10:29:57 +00:00
|
|
|
|
$variables['link'] = check_url(url($path, $url_options));
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-26 19:16:54 +00:00
|
|
|
|
$variables['langcode'] = String::checkPlain(\Drupal::languageManager()->getCurrentLanguage()->id);
|
2013-07-13 10:29:57 +00:00
|
|
|
|
$variables['namespaces'] = new Attribute($style->namespaces);
|
|
|
|
|
$variables['items'] = $items;
|
|
|
|
|
$variables['channel_elements'] = format_xml_elements($style->channel_elements);
|
2009-05-17 11:16:51 +00:00
|
|
|
|
|
|
|
|
|
// During live preview we don't want to output the header since the contents
|
|
|
|
|
// of the feed are being displayed inside a normal HTML page.
|
2013-07-13 10:29:57 +00:00
|
|
|
|
if (empty($variables['view']->live_preview)) {
|
|
|
|
|
$variables['view']->getResponse()->headers->set('Content-Type', 'application/rss+xml; charset=utf-8');
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2013-05-24 17:21:31 +00:00
|
|
|
|
* Prepares variables for views RSS item templates.
|
|
|
|
|
*
|
|
|
|
|
* Default template: views-view-row-rss.html.twig.
|
|
|
|
|
*
|
2013-07-13 10:29:57 +00:00
|
|
|
|
* @param array $variables
|
2013-05-24 17:21:31 +00:00
|
|
|
|
* An associative array containing:
|
|
|
|
|
* - row: The raw results rows.
|
2009-05-17 11:16:51 +00:00
|
|
|
|
*/
|
2013-07-13 10:29:57 +00:00
|
|
|
|
function template_preprocess_views_view_row_rss(&$variables) {
|
|
|
|
|
$item = $variables['row'];
|
2009-05-17 11:16:51 +00:00
|
|
|
|
|
2014-02-13 11:53:32 +00:00
|
|
|
|
$variables['title'] = String::checkPlain($item->title);
|
2013-07-13 10:29:57 +00:00
|
|
|
|
$variables['link'] = check_url($item->link);
|
2014-02-13 11:53:32 +00:00
|
|
|
|
$variables['description'] = String::checkPlain($item->description);
|
2013-07-13 10:29:57 +00:00
|
|
|
|
$variables['item_elements'] = empty($item->elements) ? '' : format_xml_elements($item->elements);
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2013-05-24 17:23:17 +00:00
|
|
|
|
* Prepares variables for views exposed form templates.
|
|
|
|
|
*
|
|
|
|
|
* Default template: views-exposed-form.html.twig.
|
|
|
|
|
*
|
2013-07-13 10:29:57 +00:00
|
|
|
|
* @param array $variables
|
2013-05-24 17:23:17 +00:00
|
|
|
|
* An associative array containing:
|
|
|
|
|
* - form: A render element representing the form.
|
2009-05-17 11:16:51 +00:00
|
|
|
|
*/
|
2013-07-13 10:29:57 +00:00
|
|
|
|
function template_preprocess_views_exposed_form(&$variables) {
|
|
|
|
|
$form = &$variables['form'];
|
2009-05-17 11:16:51 +00:00
|
|
|
|
|
|
|
|
|
if (!empty($form['q'])) {
|
2013-07-13 10:29:57 +00:00
|
|
|
|
$variables['q'] = $form['q'];
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-18 22:53:52 +00:00
|
|
|
|
// Include basic theming for exposed forms.
|
|
|
|
|
$form['#attached']['library'][] = array('views', 'views.exposed-form');
|
2012-08-18 20:53:41 +00:00
|
|
|
|
|
2013-08-14 12:21:01 +00:00
|
|
|
|
foreach ($form['#info'] as $info) {
|
2009-05-17 11:16:51 +00:00
|
|
|
|
if (!empty($info['label'])) {
|
2013-07-18 22:53:52 +00:00
|
|
|
|
$form[$info['value']]['#title'] = $info['label'];
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-28 12:34:28 +00:00
|
|
|
|
/**
|
2013-08-22 11:07:26 +00:00
|
|
|
|
* Prepares variables for views mini-pager templates.
|
|
|
|
|
*
|
|
|
|
|
* Default template: views-mini-pager.html.twig.
|
|
|
|
|
*
|
|
|
|
|
* @param array $variables
|
|
|
|
|
* An associative array containing:
|
|
|
|
|
* - tags: Provides link text for the next/previous links.
|
|
|
|
|
* - element: The pager's id.
|
|
|
|
|
* - parameters: Any extra GET parameters that should be retained, such as
|
|
|
|
|
* exposed input.
|
2013-06-28 12:34:28 +00:00
|
|
|
|
*/
|
2013-08-22 11:07:26 +00:00
|
|
|
|
function template_preprocess_views_mini_pager(&$variables) {
|
2009-05-17 11:16:51 +00:00
|
|
|
|
global $pager_page_array, $pager_total;
|
|
|
|
|
|
2013-07-13 10:29:57 +00:00
|
|
|
|
$tags = &$variables['tags'];
|
|
|
|
|
$element = $variables['element'];
|
|
|
|
|
$parameters = $variables['parameters'];
|
2009-05-17 11:16:51 +00:00
|
|
|
|
|
2013-06-28 12:34:28 +00:00
|
|
|
|
// Fill in default link labels.
|
|
|
|
|
$tags += array(
|
|
|
|
|
1 => t('‹‹'),
|
|
|
|
|
3 => t('››'),
|
|
|
|
|
);
|
|
|
|
|
|
2013-02-18 11:21:07 +00:00
|
|
|
|
// Current is the page we are currently paged to.
|
2009-05-17 11:16:51 +00:00
|
|
|
|
$pager_current = $pager_page_array[$element] + 1;
|
2013-06-28 12:34:28 +00:00
|
|
|
|
$current_path = current_path();
|
2009-05-17 11:16:51 +00:00
|
|
|
|
|
2013-01-23 13:44:55 +00:00
|
|
|
|
$li_previous = array();
|
|
|
|
|
if ($pager_total[$element] > 1 && $pager_page_array[$element] > 0) {
|
|
|
|
|
$li_previous = array(
|
2013-06-28 12:34:28 +00:00
|
|
|
|
'#type' => 'link',
|
|
|
|
|
'#title' => $tags[1],
|
|
|
|
|
'#href' => $current_path,
|
|
|
|
|
'#options' => array(
|
|
|
|
|
'query' => pager_query_add_page($parameters, $element, $pager_page_array[$element] - 1),
|
|
|
|
|
'attributes' => array(
|
|
|
|
|
'title' => t('Go to previous page'),
|
|
|
|
|
'rel' => 'prev',
|
|
|
|
|
),
|
|
|
|
|
// Below is ignored by default, supplied to support hook_link_alter
|
|
|
|
|
// implementations.
|
|
|
|
|
'pager_context' => array(
|
|
|
|
|
'link_type' => 'previous',
|
|
|
|
|
'element' => $element,
|
|
|
|
|
'interval' => -1,
|
|
|
|
|
),
|
|
|
|
|
),
|
2009-05-17 11:16:51 +00:00
|
|
|
|
);
|
2013-01-23 13:44:55 +00:00
|
|
|
|
}
|
2009-05-17 11:16:51 +00:00
|
|
|
|
|
2013-01-23 13:44:55 +00:00
|
|
|
|
$li_next = array();
|
|
|
|
|
if ($pager_page_array[$element] < ($pager_total[$element] - 1)) {
|
|
|
|
|
$li_next = array(
|
2013-06-28 12:34:28 +00:00
|
|
|
|
'#type' => 'link',
|
|
|
|
|
'#title' => $tags[3],
|
|
|
|
|
'#href' => $current_path,
|
|
|
|
|
'#options' => array(
|
|
|
|
|
'query' => pager_query_add_page($parameters, $element, $pager_page_array[$element] + 1),
|
|
|
|
|
'attributes' => array(
|
|
|
|
|
'title' => t('Go to next page'),
|
|
|
|
|
'rel' => 'next',
|
|
|
|
|
),
|
|
|
|
|
// Below is ignored by default, supplied to support hook_link_alter
|
|
|
|
|
// implementations.
|
|
|
|
|
'pager_context' => array(
|
2013-07-24 20:35:15 +00:00
|
|
|
|
'link_type' => 'next',
|
2013-06-28 12:34:28 +00:00
|
|
|
|
'element' => $element,
|
|
|
|
|
'interval' => 1,
|
|
|
|
|
),
|
|
|
|
|
),
|
2009-05-17 11:16:51 +00:00
|
|
|
|
);
|
|
|
|
|
}
|
2013-01-23 13:44:55 +00:00
|
|
|
|
|
2013-07-31 20:22:21 +00:00
|
|
|
|
// Don't show the pager if there is neither a next page nor a previous page
|
|
|
|
|
// link, which means that we are on the first page and there is no next page
|
|
|
|
|
// available/wanted.
|
|
|
|
|
if (empty($li_next) && empty($li_previous)) {
|
2013-08-22 11:07:26 +00:00
|
|
|
|
return;
|
2013-07-31 20:22:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-08-22 11:07:26 +00:00
|
|
|
|
$items = array();
|
2013-01-23 13:44:55 +00:00
|
|
|
|
$items[] = array(
|
|
|
|
|
'#wrapper_attributes' => array('class' => array('pager-previous')),
|
|
|
|
|
) + $li_previous;
|
|
|
|
|
|
|
|
|
|
$items[] = array(
|
|
|
|
|
'#wrapper_attributes' => array('class' => array('pager-current')),
|
2013-02-18 11:21:07 +00:00
|
|
|
|
'#markup' => t('Page @current', array('@current' => $pager_current)),
|
2013-01-23 13:44:55 +00:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$items[] = array(
|
|
|
|
|
'#wrapper_attributes' => array('class' => array('pager-next')),
|
|
|
|
|
) + $li_next;
|
|
|
|
|
|
2013-08-22 11:07:26 +00:00
|
|
|
|
$variables['items'] = array(
|
2013-06-28 12:34:28 +00:00
|
|
|
|
'#theme' => 'item_list__pager',
|
2013-06-09 20:45:55 +00:00
|
|
|
|
'#items' => $items,
|
2013-08-22 11:07:26 +00:00
|
|
|
|
'#attributes' => array('class' => array('pager')),
|
2013-01-23 13:44:55 +00:00
|
|
|
|
);
|
2009-05-17 11:16:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @defgroup views_templates Views template files
|
|
|
|
|
* @{
|
|
|
|
|
* All views templates can be overridden with a variety of names, using
|
|
|
|
|
* the view, the display ID of the view, the display type of the view,
|
|
|
|
|
* or some combination thereof.
|
|
|
|
|
*
|
|
|
|
|
* For each view, there will be a minimum of two templates used. The first
|
2013-05-25 05:13:58 +00:00
|
|
|
|
* is used for all views: views-view.html.twig.
|
2009-05-17 11:16:51 +00:00
|
|
|
|
*
|
|
|
|
|
* The second template is determined by the style selected for the view. Note
|
|
|
|
|
* that certain aspects of the view can also change which style is used; for
|
|
|
|
|
* example, arguments which provide a summary view might change the style to
|
|
|
|
|
* one of the special summary styles.
|
|
|
|
|
*
|
2013-05-24 17:25:24 +00:00
|
|
|
|
* The default style for all views is views-view-unformatted.html.twig.
|
2009-05-17 11:16:51 +00:00
|
|
|
|
*
|
|
|
|
|
* Many styles will then farm out the actual display of each row to a row
|
2013-10-03 20:55:34 +00:00
|
|
|
|
* style; the default row style is views-view-fields.html.twig.
|
2009-05-17 11:16:51 +00:00
|
|
|
|
*
|
|
|
|
|
* Here is an example of all the templates that will be tried in the following
|
|
|
|
|
* case:
|
|
|
|
|
*
|
|
|
|
|
* View, named foobar. Style: unformatted. Row style: Fields. Display: Page.
|
|
|
|
|
*
|
2013-10-03 20:55:34 +00:00
|
|
|
|
* - views-view--foobar--page.html.twig
|
|
|
|
|
* - views-view--page.html.twig
|
|
|
|
|
* - views-view--foobar.html.twig
|
2013-05-25 05:13:58 +00:00
|
|
|
|
* - views-view.html.twig
|
2009-05-17 11:16:51 +00:00
|
|
|
|
*
|
2013-05-24 17:25:24 +00:00
|
|
|
|
* - views-view-unformatted--foobar--page.html.twig
|
|
|
|
|
* - views-view-unformatted--page.html.twig
|
|
|
|
|
* - views-view-unformatted--foobar.html.twig
|
|
|
|
|
* - views-view-unformatted.html.twig
|
2009-05-17 11:16:51 +00:00
|
|
|
|
*
|
2013-10-03 20:55:34 +00:00
|
|
|
|
* - views-view-fields--foobar--page.html.twig
|
|
|
|
|
* - views-view-fields--page.html.twig
|
|
|
|
|
* - views-view-fields--foobar.html.twig
|
|
|
|
|
* - views-view-fields.html.twig
|
2009-05-17 11:16:51 +00:00
|
|
|
|
*
|
|
|
|
|
* Important! When adding a new template to your theme, be sure to flush the
|
|
|
|
|
* theme registry cache!
|
|
|
|
|
*
|
2013-06-28 06:14:39 +00:00
|
|
|
|
* @see \Drupal\views\ViewExecutable::buildThemeFunctions()
|
2009-05-17 11:16:51 +00:00
|
|
|
|
* @}
|
|
|
|
|
*/
|