Projet

Général

Profil

Paste
Télécharger (1,77 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / views / modules / aggregator / views_handler_field_aggregator_category.inc @ 5d12d676

1
<?php
2

    
3
/**
4
 * @file
5
 * Definition of views_handler_field_aggregator_category.
6
 */
7

    
8
/**
9
 * Field handler to provide simple renderer that allows linking to aggregator
10
 * category.
11
 *
12
 * @ingroup views_field_handlers
13
 */
14
class views_handler_field_aggregator_category extends views_handler_field {
15

    
16
  /**
17
   * Constructor to provide additional field to add.
18
   */
19
  public function construct() {
20
    parent::construct();
21
    $this->additional_fields['cid'] = 'cid';
22
  }
23

    
24
  /**
25
   * {@inheritdoc}
26
   */
27
  public function option_definition() {
28
    $options = parent::option_definition();
29
    $options['link_to_category'] = array('default' => FALSE, 'bool' => TRUE);
30
    return $options;
31
  }
32

    
33
  /**
34
   * Provide link to category option
35
   */
36
  public function options_form(&$form, &$form_state) {
37
    $form['link_to_category'] = array(
38
      '#title' => t('Link this field to its aggregator category page'),
39
      '#description' => t('This will override any other link you have set.'),
40
      '#type' => 'checkbox',
41
      '#default_value' => !empty($this->options['link_to_category']),
42
    );
43
    parent::options_form($form, $form_state);
44
  }
45

    
46
  /**
47
   * Render whatever the data is as a link to the category.
48
   *
49
   * Data should be made XSS safe prior to calling this function.
50
   */
51
  public function render_link($data, $values) {
52
    $cid = $this->get_value($values, 'cid');
53
    if (!empty($this->options['link_to_category']) && !empty($cid) && $data !== NULL && $data !== '') {
54
      $this->options['alter']['make_link'] = TRUE;
55
      $this->options['alter']['path'] = "aggregator/category/$cid";
56
    }
57
    return $data;
58
  }
59

    
60
  /**
61
   * {@inheritdoc}
62
   */
63
  public function render($values) {
64
    $value = $this->get_value($values);
65
    return $this->render_link($this->sanitize_value($value), $values);
66
  }
67

    
68
}