views_handler_field_contextual_links.inc 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * @file
  4. * Definition of views_handler_field_contextual_links.
  5. */
  6. /**
  7. * Provides a handler that adds contextual links.
  8. *
  9. * @ingroup views_field_handlers
  10. */
  11. class views_handler_field_contextual_links extends views_handler_field_links {
  12. /**
  13. * {@inheritdoc}
  14. */
  15. public function pre_render(&$values) {
  16. // Add a row plugin css class for the contextual link.
  17. $class = 'contextual-links-region';
  18. if (!empty($this->view->style_plugin->options['row_class'])) {
  19. $this->view->style_plugin->options['row_class'] .= " $class";
  20. }
  21. else {
  22. $this->view->style_plugin->options['row_class'] = $class;
  23. }
  24. }
  25. /**
  26. * {@inheritdoc}
  27. */
  28. public function options_form(&$form, &$form_state) {
  29. parent::options_form($form, $form_state);
  30. $form['fields']['#description'] = t('Fields to be included as contextual links.');
  31. $form['destination']['#description'] = t('Include a "destination" parameter in the link to return the user to the original view upon completing the contextual action.');
  32. }
  33. /**
  34. * Render the contextual fields.
  35. */
  36. public function render($values) {
  37. $links = $this->get_links();
  38. if (!empty($links)) {
  39. $build = array(
  40. '#prefix' => '<div class="contextual-links-wrapper">',
  41. '#suffix' => '</div>',
  42. '#theme' => 'links__contextual',
  43. '#links' => $links,
  44. '#attributes' => array('class' => array('contextual-links')),
  45. '#attached' => array(
  46. 'library' => array(array('contextual', 'contextual-links')),
  47. ),
  48. '#access' => user_access('access contextual links'),
  49. );
  50. return drupal_render($build);
  51. }
  52. else {
  53. return '';
  54. }
  55. }
  56. }