Projet

Général

Profil

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

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

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
class ldap_views_handler_field extends views_handler_field {
11

    
12
  function render($values) {
13
    return array_key_exists($this->field_alias, $values) ? check_plain($values[$this->field_alias]) : '';
14
  }
15

    
16
  function element_type($none_supported = FALSE, $default_empty = FALSE, $inline = FALSE) {
17
    if (isset($this->definition['element type'])) {
18
      return $this->definition['element type'];
19
    }
20

    
21
    return 'div';
22
  }
23

    
24
  function option_definition() {
25
    $options = parent::option_definition();
26
    $options['multivalue']      = array('default' => 'v-all');
27
    $options['value_separator'] = array('default' => '');
28
    $options['index_value']     = array('default' => 0);
29
    return $options;
30
  }
31

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