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_attribute extends ldap_views_handler_field {
|
14
|
|
15
|
/**
|
16
|
*
|
17
|
*/
|
18
|
public function option_definition() {
|
19
|
$options = parent::option_definition();
|
20
|
$options['attribute_name'] = ['default' => ''];
|
21
|
return $options;
|
22
|
}
|
23
|
|
24
|
/**
|
25
|
* Add the field for the LDAP Attribute.
|
26
|
*/
|
27
|
public function options_form(&$form, &$form_state) {
|
28
|
$ldap_data = new LdapQuery(ldap_views_get_qid($this->view));
|
29
|
|
30
|
if (empty($ldap_data)) {
|
31
|
$form['attribute_name'] = [
|
32
|
'#markup' => 'You must select a valid LDAP search (Advanced::Query settings)',
|
33
|
];
|
34
|
return;
|
35
|
}
|
36
|
|
37
|
parent::options_form($form, $form_state);
|
38
|
|
39
|
$options = [];
|
40
|
foreach ($ldap_data->attributes as $attribute) {
|
41
|
$options[$attribute] = $attribute;
|
42
|
}
|
43
|
|
44
|
$form['attribute_name'] = [
|
45
|
'#type' => 'select',
|
46
|
'#title' => t('Attribute name'),
|
47
|
'#description' => t('The attribute name from LDAP response'),
|
48
|
'#options' => $options,
|
49
|
'#default_value' => $this->options['attribute_name'],
|
50
|
'#required' => TRUE,
|
51
|
];
|
52
|
}
|
53
|
|
54
|
/**
|
55
|
* Called to add the field to a query.
|
56
|
*/
|
57
|
public function query() {
|
58
|
$this->real_field = $this->options['attribute_name'];
|
59
|
parent::query();
|
60
|
}
|
61
|
|
62
|
}
|