views_handler_field_contextual_links.inc 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. function pre_render(&$values) {
  13. // Add a row plugin css class for the contextual link.
  14. $class = 'contextual-links-region';
  15. if (!empty($this->view->style_plugin->options['row_class'])) {
  16. $this->view->style_plugin->options['row_class'] .= " $class";
  17. }
  18. else {
  19. $this->view->style_plugin->options['row_class'] = $class;
  20. }
  21. }
  22. function options_form(&$form, &$form_state) {
  23. parent::options_form($form, $form_state);
  24. $form['fields']['#description'] = t('Fields to be included as contextual links.');
  25. $form['destination']['#description'] = t('Include a "destination" parameter in the link to return the user to the original view upon completing the contextual action.');
  26. }
  27. /**
  28. * Render the contextual fields.
  29. */
  30. function render($values) {
  31. $links = $this->get_links();
  32. if (!empty($links)) {
  33. $build = array(
  34. '#prefix' => '<div class="contextual-links-wrapper">',
  35. '#suffix' => '</div>',
  36. '#theme' => 'links__contextual',
  37. '#links' => $links,
  38. '#attributes' => array('class' => array('contextual-links')),
  39. '#attached' => array(
  40. 'library' => array(array('contextual', 'contextual-links')),
  41. ),
  42. '#access' => user_access('access contextual links'),
  43. );
  44. return drupal_render($build);
  45. }
  46. else {
  47. return '';
  48. }
  49. }
  50. }