views_handler_field_ctools_dropdown.inc 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * @file
  4. * Definition of views_handler_field_ctools_dropdown.
  5. */
  6. /**
  7. * Field handler which displays some amount of links as ctools dropdown button.
  8. *
  9. * @ingroup views_field_handlers
  10. */
  11. class views_handler_field_ctools_dropdown extends views_handler_field_links {
  12. /**
  13. * {@inheritdoc}
  14. */
  15. public function option_definition() {
  16. $options = parent::option_definition();
  17. $options['views_admin_css'] = array('default' => TRUE, 'bool' => TRUE);
  18. return $options;
  19. }
  20. /**
  21. * {@inheritdoc}
  22. */
  23. public function options_form(&$form, &$form_state) {
  24. parent::options_form($form, $form_state);
  25. $form['fields']['#description'] = t('Fields to be included as ctools dropdown button.');
  26. $form['destination']['#description'] = t('Include a "destination" parameter in the link to return the user to the original view upon completing a link action.');
  27. $form['views_admin_css'] = array(
  28. '#type' => 'checkbox',
  29. '#title' => t('Include Views admin CSS'),
  30. '#description' => t("Add additional css to match the style of the Views admin screen."),
  31. '#default_value' => $this->options['views_admin_css'],
  32. );
  33. }
  34. /**
  35. * Render the dropdown button.
  36. */
  37. public function render($values) {
  38. static $added_admin_css;
  39. $links = $this->get_links();
  40. if (!empty($links)) {
  41. if (!empty($this->options['views_admin_css']) && !$added_admin_css) {
  42. views_include('admin');
  43. views_ui_add_admin_css();
  44. $added_admin_css = TRUE;
  45. }
  46. $vars = array(
  47. 'links' => $links,
  48. 'attributes' => array(
  49. 'class' => array(
  50. 'links',
  51. 'inline',
  52. ),
  53. ),
  54. );
  55. return theme('links__ctools_dropbutton', $vars);
  56. }
  57. else {
  58. return '';
  59. }
  60. }
  61. }