Projet

Général

Profil

Paste
Télécharger (2,19 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / ldap / ldap_views / handlers / ldap_views_handler_field.inc @ 32700c57

1
<?php
2

    
3
/**
4
 * @file
5
 * LDAP field handler.
6
 *
7
 * Defines a new class field handler for a default ldap field.
8
 */
9

    
10
/**
11
 *
12
 */
13
class ldap_views_handler_field extends views_handler_field {
14

    
15
  /**
16
   *
17
   */
18
  public function render($values) {
19
    return array_key_exists($this->field_alias, $values) ? check_plain($values[$this->field_alias]) : '';
20
  }
21

    
22
  /**
23
   *
24
   */
25
  public function element_type($none_supported = FALSE, $default_empty = FALSE, $inline = FALSE) {
26
    if (isset($this->definition['element type'])) {
27
      return $this->definition['element type'];
28
    }
29

    
30
    return 'div';
31
  }
32

    
33
  /**
34
   *
35
   */
36
  public function option_definition() {
37
    $options                    = parent::option_definition();
38
    $options['multivalue']      = ['default' => 'v-all'];
39
    $options['value_separator'] = ['default' => ''];
40
    $options['index_value']     = ['default' => 0];
41
    return $options;
42
  }
43

    
44
  /**
45
   * Add the field for the LDAP Attribute.
46
   */
47
  public function options_form(&$form, &$form_state) {
48
    parent::options_form($form, $form_state);
49
    $form['multivalue'] = [
50
    // It should be 'radios', but it makes #dependency not to work.
51
      '#type' => 'select',
52
      '#title' => t('Values to show'),
53
      '#description' => t('What to do whith  multivalue attributes'),
54
      '#options' => [
55
        'v-all' => t('All values'),
56
        'v-index' => t('Show Nth value'),
57
        'v-count' => t('Count values'),
58
      ],
59
      '#default_value' => $this->options['multivalue'],
60
      '#required' => TRUE,
61
    ];
62
    $form['value_separator'] = [
63
      '#type' => 'textfield',
64
      '#title' => t('Value separator'),
65
      '#description' => t('Separator to use between values in multivalued attributes'),
66
      '#default_value' => $this->options['value_separator'],
67
      '#dependency' => [
68
        'edit-options-multivalue' => ['v-all'],
69
      ],
70
    ];
71
    $form['index_value'] = [
72
      '#type' => 'textfield',
73
      '#title' => t('Index'),
74
      '#description' => t('Index of the value to show. Use negative numbers to index from last item (0=First, -1=Last)'),
75
      '#default_value' => $this->options['index_value'],
76
      '#dependency' => [
77
        'edit-options-multivalue' => ['v-index'],
78
      ],
79
    ];
80
  }
81

    
82
}