views_handler_field_custom.inc

  1. 3.x handlers/views_handler_field_custom.inc
  2. 2.x handlers/views_handler_field_custom.inc

Definition of views_handler_field_custom.

File

handlers/views_handler_field_custom.inc
View source
  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. function query() {
  13. // do nothing -- to override the parent query.
  14. }
  15. function option_definition() {
  16. $options = parent::option_definition();
  17. // Override the alter text option to always alter the text.
  18. $options['alter']['contains']['alter_text'] = array('default' => TRUE, 'bool' => TRUE);
  19. $options['hide_alter_empty'] = array('default' => FALSE, 'bool' => TRUE);
  20. return $options;
  21. }
  22. function options_form(&$form, &$form_state) {
  23. parent::options_form($form, $form_state);
  24. // Remove the checkbox
  25. unset($form['alter']['alter_text']);
  26. unset($form['alter']['text']['#dependency']);
  27. unset($form['alter']['text']['#process']);
  28. unset($form['alter']['help']['#dependency']);
  29. unset($form['alter']['help']['#process']);
  30. $form['#pre_render'][] = 'views_handler_field_custom_pre_render_move_text';
  31. }
  32. function render($values) {
  33. // Return the text, so the code never thinks the value is empty.
  34. return $this->options['alter']['text'];
  35. }
  36. }
  37. /**
  38. * Prerender function to move the textarea to the top.
  39. */
  40. function views_handler_field_custom_pre_render_move_text($form) {
  41. $form['text'] = $form['alter']['text'];
  42. $form['help'] = $form['alter']['help'];
  43. unset($form['alter']['text']);
  44. unset($form['alter']['help']);
  45. return $form;
  46. }