views_handler_area_text.inc

Definition of views_handler_area_text.

File

handlers/views_handler_area_text.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Definition of views_handler_area_text.
  5. */
  6. /**
  7. * Views area text handler.
  8. *
  9. * @ingroup views_area_handlers
  10. */
  11. class views_handler_area_text extends views_handler_area {
  12. function option_definition() {
  13. $options = parent::option_definition();
  14. $options['content'] = array('default' => '', 'translatable' => TRUE, 'format_key' => 'format');
  15. $options['format'] = array('default' => NULL);
  16. $options['tokenize'] = array('default' => FALSE, 'bool' => TRUE);
  17. return $options;
  18. }
  19. function options_form(&$form, &$form_state) {
  20. parent::options_form($form, $form_state);
  21. $form['content'] = array(
  22. '#type' => 'text_format',
  23. '#default_value' => $this->options['content'],
  24. '#rows' => 6,
  25. '#format' => isset($this->options['format']) ? $this->options['format'] : filter_default_format(),
  26. '#wysiwyg' => FALSE,
  27. );
  28. // @TODO: Refactor token handling into a base class.
  29. $form['tokenize'] = array(
  30. '#type' => 'checkbox',
  31. '#title' => t('Use replacement tokens from the first row'),
  32. '#default_value' => $this->options['tokenize'],
  33. );
  34. // Get a list of the available fields and arguments for token replacement.
  35. $options = array();
  36. foreach ($this->view->display_handler->get_handlers('field') as $field => $handler) {
  37. $options[t('Fields')]["[$field]"] = $handler->ui_name();
  38. }
  39. $count = 0; // This lets us prepare the key as we want it printed.
  40. foreach ($this->view->display_handler->get_handlers('argument') as $arg => $handler) {
  41. $options[t('Arguments')]['%' . ++$count] = t('@argument title', array('@argument' => $handler->ui_name()));
  42. $options[t('Arguments')]['!' . $count] = t('@argument input', array('@argument' => $handler->ui_name()));
  43. }
  44. if (!empty($options)) {
  45. $output = '<p>' . t('The following tokens are available. If you would like to have the characters \'[\' and \']\' please use the html entity codes \'%5B\' or \'%5D\' or they will get replaced with empty space.' . '</p>');
  46. foreach (array_keys($options) as $type) {
  47. if (!empty($options[$type])) {
  48. $items = array();
  49. foreach ($options[$type] as $key => $value) {
  50. $items[] = $key . ' == ' . check_plain($value);
  51. }
  52. $output .= theme('item_list',
  53. array(
  54. 'items' => $items,
  55. 'type' => $type
  56. ));
  57. }
  58. }
  59. $form['token_help'] = array(
  60. '#type' => 'fieldset',
  61. '#title' => t('Replacement patterns'),
  62. '#collapsible' => TRUE,
  63. '#collapsed' => TRUE,
  64. '#value' => $output,
  65. '#id' => 'edit-options-token-help',
  66. '#dependency' => array(
  67. 'edit-options-tokenize' => array(1),
  68. ),
  69. '#prefix' => '<div>',
  70. '#suffix' => '</div>',
  71. );
  72. }
  73. }
  74. function options_submit(&$form, &$form_state) {
  75. $form_state['values']['options']['format'] = $form_state['values']['options']['content']['format'];
  76. $form_state['values']['options']['content'] = $form_state['values']['options']['content']['value'];
  77. parent::options_submit($form, $form_state);
  78. }
  79. function render($empty = FALSE) {
  80. $format = isset($this->options['format']) ? $this->options['format'] : filter_default_format();
  81. if (!$empty || !empty($this->options['empty'])) {
  82. return $this->render_textarea($this->options['content'], $format);
  83. }
  84. return '';
  85. }
  86. /**
  87. * Render a text area, using the proper format.
  88. */
  89. function render_textarea($value, $format) {
  90. if ($value) {
  91. if ($this->options['tokenize']) {
  92. $value = $this->view->style_plugin->tokenize_value($value, 0);
  93. }
  94. return check_markup($value, $format, '', FALSE);
  95. }
  96. }
  97. }