views_handler_field_custom.inc 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * @file
  4. * Definition of views_handler_field_custom.
  5. */
  6. /**
  7. * A handler to provide a field that is completely custom by the administrator.
  8. *
  9. * @ingroup views_field_handlers
  10. */
  11. class views_handler_field_custom extends views_handler_field {
  12. /**
  13. * {@inheritdoc}
  14. */
  15. public function query() {
  16. // Do nothing -- to override the parent query.
  17. }
  18. /**
  19. * {@inheritdoc}
  20. */
  21. public function option_definition() {
  22. $options = parent::option_definition();
  23. // Override the alter text option to always alter the text.
  24. $options['alter']['contains']['alter_text'] = array('default' => TRUE, 'bool' => TRUE);
  25. $options['hide_alter_empty'] = array('default' => FALSE, 'bool' => TRUE);
  26. return $options;
  27. }
  28. /**
  29. * {@inheritdoc}
  30. */
  31. public function options_form(&$form, &$form_state) {
  32. parent::options_form($form, $form_state);
  33. // Remove the checkbox.
  34. unset($form['alter']['alter_text']);
  35. unset($form['alter']['text']['#dependency']);
  36. unset($form['alter']['text']['#process']);
  37. unset($form['alter']['help']['#dependency']);
  38. unset($form['alter']['help']['#process']);
  39. $form['#pre_render'][] = 'views_handler_field_custom_pre_render_move_text';
  40. }
  41. /**
  42. * {@inheritdoc}
  43. */
  44. public function render($values) {
  45. // Return the text, so the code never thinks the value is empty.
  46. return $this->options['alter']['text'];
  47. }
  48. }
  49. /**
  50. * Prerender function to move the textarea to the top.
  51. */
  52. function views_handler_field_custom_pre_render_move_text($form) {
  53. $form['text'] = $form['alter']['text'];
  54. $form['help'] = $form['alter']['help'];
  55. unset($form['alter']['text']);
  56. unset($form['alter']['help']);
  57. return $form;
  58. }