DefaultSummary.php 2.75 KB
Newer Older
merlinofchaos's avatar
merlinofchaos committed
1 2 3 4
<?php

/**
 * @file
5
 * Definition of Drupal\views\Plugin\views\style\StyleSummaryPluginBase.
merlinofchaos's avatar
merlinofchaos committed
6 7
 */

8
namespace Drupal\views\Plugin\views\style;
9

10
use Drupal\views\Plugin\views\style\StylePluginBase;
11 12
use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
13

merlinofchaos's avatar
merlinofchaos committed
14 15 16 17 18
/**
 * The default style plugin for summaries.
 *
 * @ingroup views_style_plugins
 */
19 20 21

/**
 * @Plugin(
aspilicious's avatar
aspilicious committed
22
 *   id = "default_summary",
23 24 25 26 27 28 29 30 31
 *   title = @Translation("List"),
 *   help = @Translation("Displays the default summary as a list."),
 *   theme = "views_view_summary",
 *   type = "summary",
 *   uses_options = TRUE,
 *   help_topic = "style-summary"
 * )
 */
class DefaultSummary extends StylePluginBase {
merlinofchaos's avatar
merlinofchaos committed
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
  function option_definition() {
    $options = parent::option_definition();

    $options['base_path'] = array('default' => '');
    $options['count'] = array('default' => TRUE, 'bool' => TRUE);
    $options['override'] = array('default' => FALSE, 'bool' => TRUE);
    $options['items_per_page'] = array('default' => 25);

    return $options;
  }

  function query() {
    if (!empty($this->options['override'])) {
      $this->view->set_items_per_page(intval($this->options['items_per_page']));
    }
  }

  function options_form(&$form, &$form_state) {
    $form['base_path'] = array(
      '#type' => 'textfield',
      '#title' => t('Base path'),
      '#default_value' => $this->options['base_path'],
      '#description' => t('Define the base path for links in this summary
        view, i.e. http://example.com/<strong>your_view_path/archive</strong>.
        Do not include beginning and ending forward slash. If this value
        is empty, views will use the first path found as the base path,
        in page displays, or / if no path could be found.'),
    );
    $form['count'] = array(
      '#type' => 'checkbox',
      '#default_value' => !empty($this->options['count']),
      '#title' => t('Display record count with link'),
    );
    $form['override'] = array(
      '#type' => 'checkbox',
      '#default_value' => !empty($this->options['override']),
      '#title' => t('Override number of items to display'),
    );

    $form['items_per_page'] = array(
      '#type' => 'textfield',
      '#title' => t('Items to display'),
      '#default_value' => $this->options['items_per_page'],
75 76
      '#states' => array(
        'visible' => array(
77
          ':input[name="options[summary][options][' . $this->definition['id'] . '][override]"]' => array('checked' => TRUE),
78
        ),
merlinofchaos's avatar
merlinofchaos committed
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
      ),
    );
  }

  function render() {
    $rows = array();
    foreach ($this->view->result as $row) {
      // @todo: Include separator as an option.
      $rows[] = $row;
    }

    return theme($this->theme_functions(), array(
      'view' => $this->view,
      'options' => $this->options,
      'rows' => $rows
    ));
  }
}