Project

General

Profile

Paste
Download (1.67 KB) Statistics
| Branch: | Revision:

root / drupal7 / sites / all / modules / views / handlers / views_handler_field_contextual_links.inc @ 4003efde

1
<?php
2

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

    
8
/**
9
 * Provides a handler that adds contextual links.
10
 *
11
 * @ingroup views_field_handlers
12
 */
13
class views_handler_field_contextual_links extends views_handler_field_links {
14

    
15
  /**
16
   * {@inheritdoc}
17
   */
18
  public function pre_render(&$values) {
19
    // Add a row plugin css class for the contextual link.
20
    $class = 'contextual-links-region';
21
    if (!empty($this->view->style_plugin->options['row_class'])) {
22
      $this->view->style_plugin->options['row_class'] .= " $class";
23
    }
24
    else {
25
      $this->view->style_plugin->options['row_class'] = $class;
26
    }
27
  }
28

    
29
  /**
30
   * {@inheritdoc}
31
   */
32
  public function options_form(&$form, &$form_state) {
33
    parent::options_form($form, $form_state);
34

    
35
    $form['fields']['#description'] = t('Fields to be included as contextual links.');
36
    $form['destination']['#description'] = t('Include a "destination" parameter in the link to return the user to the original view upon completing the contextual action.');
37
  }
38

    
39
  /**
40
   * Render the contextual fields.
41
   */
42
  public function render($values) {
43
    $links = $this->get_links();
44
    if (!empty($links)) {
45
      $build = array(
46
        '#prefix' => '<div class="contextual-links-wrapper">',
47
        '#suffix' => '</div>',
48
        '#theme' => 'links__contextual',
49
        '#links' => $links,
50
        '#attributes' => array('class' => array('contextual-links')),
51
        '#attached' => array(
52
          'library' => array(array('contextual', 'contextual-links')),
53
        ),
54
        '#access' => user_access('access contextual links'),
55
      );
56
      return drupal_render($build);
57
    }
58
    else {
59
      return '';
60
    }
61
  }
62

    
63
}