Projet

Général

Profil

Paste
Télécharger (1,68 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / views / handlers / views_handler_field_custom.inc @ 4003efde

1
<?php
2

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

    
8
/**
9
 * A handler to provide a field that is completely custom by the administrator.
10
 *
11
 * @ingroup views_field_handlers
12
 */
13
class views_handler_field_custom extends views_handler_field {
14

    
15
  /**
16
   * {@inheritdoc}
17
   */
18
  public function query() {
19
    // Do nothing -- to override the parent query.
20
  }
21

    
22
  /**
23
   * {@inheritdoc}
24
   */
25
  public function option_definition() {
26
    $options = parent::option_definition();
27

    
28
    // Override the alter text option to always alter the text.
29
    $options['alter']['contains']['alter_text'] = array('default' => TRUE, 'bool' => TRUE);
30
    $options['hide_alter_empty'] = array('default' => FALSE, 'bool' => TRUE);
31
    return $options;
32
  }
33

    
34
  /**
35
   * {@inheritdoc}
36
   */
37
  public function options_form(&$form, &$form_state) {
38
    parent::options_form($form, $form_state);
39

    
40
    // Remove the checkbox.
41
    unset($form['alter']['alter_text']);
42
    unset($form['alter']['text']['#dependency']);
43
    unset($form['alter']['text']['#process']);
44
    unset($form['alter']['help']['#dependency']);
45
    unset($form['alter']['help']['#process']);
46
    $form['#pre_render'][] = 'views_handler_field_custom_pre_render_move_text';
47
  }
48

    
49
  /**
50
   * {@inheritdoc}
51
   */
52
  public function render($values) {
53
    // Return the text, so the code never thinks the value is empty.
54
    return $this->options['alter']['text'];
55
  }
56

    
57
}
58

    
59
/**
60
 * Prerender function to move the textarea to the top.
61
 */
62
function views_handler_field_custom_pre_render_move_text($form) {
63
  $form['text'] = $form['alter']['text'];
64
  $form['help'] = $form['alter']['help'];
65
  unset($form['alter']['text']);
66
  unset($form['alter']['help']);
67

    
68
  return $form;
69
}