Projet

Général

Profil

Paste
Télécharger (3,69 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / views / handlers / views_handler_area_text.inc @ 76df55b7

1
<?php
2

    
3
/**
4
 * @file
5
 * Definition of views_handler_area_text.
6
 */
7

    
8
/**
9
 * Views area text handler.
10
 *
11
 * @ingroup views_area_handlers
12
 */
13
class views_handler_area_text extends views_handler_area {
14

    
15
  function option_definition() {
16
    $options = parent::option_definition();
17
    $options['content'] = array('default' => '', 'translatable' => TRUE, 'format_key' => 'format');
18
    $options['format'] = array('default' => NULL);
19
    $options['tokenize'] = array('default' => FALSE, 'bool' => TRUE);
20
    return $options;
21
  }
22

    
23
  function options_form(&$form, &$form_state) {
24
    parent::options_form($form, $form_state);
25

    
26
    $form['content'] = array(
27
      '#type' => 'text_format',
28
      '#default_value' => $this->options['content'],
29
      '#rows' => 6,
30
      '#format' => isset($this->options['format']) ? $this->options['format'] : filter_default_format(),
31
      '#wysiwyg' => FALSE,
32
    );
33

    
34
    // @TODO: Refactor token handling into a base class.
35
    $form['tokenize'] = array(
36
      '#type' => 'checkbox',
37
      '#title' => t('Use replacement tokens from the first row'),
38
      '#default_value' => $this->options['tokenize'],
39
    );
40

    
41
    // Get a list of the available fields and arguments for token replacement.
42
    $options = array();
43
    foreach ($this->view->display_handler->get_handlers('field') as $field => $handler) {
44
      $options[t('Fields')]["[$field]"] = $handler->ui_name();
45
    }
46

    
47
    $count = 0; // This lets us prepare the key as we want it printed.
48
    foreach ($this->view->display_handler->get_handlers('argument') as $arg => $handler) {
49
      $options[t('Arguments')]['%' . ++$count] = t('@argument title', array('@argument' => $handler->ui_name()));
50
      $options[t('Arguments')]['!' . $count] = t('@argument input', array('@argument' => $handler->ui_name()));
51
    }
52

    
53
    if (!empty($options)) {
54
      $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>');
55
      foreach (array_keys($options) as $type) {
56
        if (!empty($options[$type])) {
57
          $items = array();
58
          foreach ($options[$type] as $key => $value) {
59
            $items[] = $key . ' == ' . check_plain($value);
60
          }
61
          $output .= theme('item_list',
62
            array(
63
              'items' => $items,
64
              'type' => $type
65
            ));
66
        }
67
      }
68

    
69
      $form['token_help'] = array(
70
        '#type' => 'fieldset',
71
        '#title' => t('Replacement patterns'),
72
        '#collapsible' => TRUE,
73
        '#collapsed' => TRUE,
74
        '#value' => $output,
75
        '#id' => 'edit-options-token-help',
76
        '#dependency' => array(
77
          'edit-options-tokenize' => array(1),
78
        ),
79
        '#prefix' => '<div>',
80
        '#suffix' => '</div>',
81
      );
82
    }
83
  }
84

    
85
  function options_submit(&$form, &$form_state) {
86
    $form_state['values']['options']['format'] = $form_state['values']['options']['content']['format'];
87
    $form_state['values']['options']['content'] = $form_state['values']['options']['content']['value'];
88
    parent::options_submit($form, $form_state);
89
  }
90

    
91
  function render($empty = FALSE) {
92
    $format = isset($this->options['format']) ? $this->options['format'] : filter_default_format();
93
    if (!$empty || !empty($this->options['empty'])) {
94
      return $this->render_textarea($this->options['content'], $format);
95
    }
96
    return '';
97
  }
98

    
99
  /**
100
   * Render a text area, using the proper format.
101
   */
102
  function render_textarea($value, $format) {
103
    if ($value) {
104
      if ($this->options['tokenize']) {
105
        $value = $this->view->style_plugin->tokenize_value($value, 0);
106
      }
107
      return check_markup($value, $format, '', FALSE);
108
    }
109
  }
110
}