users.php
2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
defined('JPATH_PLATFORM') or die;
/**
* Field to select a user ID from a modal list.
*
* @since 1.6
*/
class JFormFieldUsers extends JFormFieldUser
{
/**
* The form field type.
*
* @var string
* @since 2.7
*/
public $type = 'Users';
/**
* Method to get the user field input markup.
*
* @return string The field input markup.
*
* @since 1.6
*/
protected function getInput()
{
if (empty($this->layout))
{
throw new \UnexpectedValueException(sprintf('%s has no layout assigned.', $this->name));
}
$options = $this->getOptions();
$name = $this->name;
// clear name
$this->name = "";
$this->onchange = "(function(){WfSelectUsers();})();";
$html = $this->getRenderer($this->layout)->render($this->getLayoutData());
$html .= '<div class="users-select">';
$html .= '<select name="' . $name . '" id="' . $this->id . '_select" class="custom-select" multiple>';
foreach ($options as $option) {
$html .= '<option value="' . $option->value . '" selected>' . $option->text . '</option>';
}
$html .= '</select>';
$html .= '</div>';
return $html;
}
/**
* Get the data that is going to be passed to the layout
*
* @return array
*
* @since 3.5
*/
public function getLayoutData()
{
// clear value
$this->value = json_encode($this->value);
// Get the basic field data
return parent::getLayoutData();
}
/**
* Allow to override renderer include paths in child fields
*
* @return array
*
* @since 3.5
*/
protected function getLayoutPaths()
{
return array(JPATH_ADMINISTRATOR . '/components/com_jce/layouts', JPATH_SITE . '/layouts');
}
/**
* Method to get the field options.
*
* @return array The field option objects
*
* @since 11.1
*/
protected function getOptions()
{
$fieldname = preg_replace('/[^a-zA-Z0-9_\-]/', '_', $this->fieldname);
$options = array();
if (empty($this->value)) {
return $options;
}
$this->value = json_decode($this->value);
foreach ($this->value as $user) {
$tmp = array(
'value' => $user->value,
'text' => JText::alt($user->text, $fieldname),
'selected' => true,
);
// Add the option object to the result set.
$options[] = (object) $tmp;
}
reset($options);
return $options;
}
}