1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Part of the Joomla Framework Form Package |
4
|
|
|
* |
5
|
|
|
* @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved. |
6
|
|
|
* @license GNU General Public License version 2 or later; see LICENSE |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Joomla\Form; |
10
|
|
|
|
11
|
|
|
use Joomla\Form\Html\Select as HtmlSelect; |
12
|
|
|
use Joomla\Language\Text; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Form Field class for the Joomla Framework. |
16
|
|
|
* Supports a generic list of options. |
17
|
|
|
* |
18
|
|
|
* @since 1.0 |
19
|
|
|
* @deprecated The joomla/form package is deprecated |
20
|
|
|
*/ |
21
|
|
|
class Field_List extends Field |
|
|
|
|
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* The form field type. |
25
|
|
|
* |
26
|
|
|
* @var string |
27
|
|
|
* @since 1.0 |
28
|
|
|
*/ |
29
|
|
|
protected $type = 'List'; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Method to get the field input markup for a generic list. |
33
|
|
|
* Use the multiple attribute to enable multiselect. |
34
|
|
|
* |
35
|
|
|
* @return string The field input markup. |
36
|
|
|
* |
37
|
|
|
* @since 1.0 |
38
|
|
|
*/ |
39
|
|
|
protected function getInput() |
40
|
|
|
{ |
41
|
|
|
$html = array(); |
42
|
|
|
$attr = ''; |
43
|
|
|
|
44
|
|
|
// Initialize some field attributes. |
45
|
|
|
$attr .= $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : ''; |
46
|
|
|
|
47
|
|
|
// To avoid user's confusion, readonly="true" should imply disabled="true". |
48
|
|
|
if ((string) $this->element['readonly'] == 'true' || (string) $this->element['disabled'] == 'true') |
49
|
|
|
{ |
50
|
|
|
$attr .= ' disabled="disabled"'; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
$attr .= $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : ''; |
54
|
|
|
$attr .= $this->multiple ? ' multiple="multiple"' : ''; |
55
|
|
|
|
56
|
|
|
// Initialize JavaScript field attributes. |
57
|
|
|
$attr .= $this->element['onchange'] ? ' onchange="' . (string) $this->element['onchange'] . '"' : ''; |
58
|
|
|
|
59
|
|
|
// Get the field options. |
60
|
|
|
$options = (array) $this->getOptions(); |
61
|
|
|
|
62
|
|
|
// Create a read-only list (no name) with a hidden input to store the value. |
63
|
|
|
if ((string) $this->element['readonly'] == 'true') |
64
|
|
|
{ |
65
|
|
|
$html[] = HtmlSelect::genericlist($options, '', trim($attr), 'value', 'text', $this->value, $this->id); |
66
|
|
|
$html[] = '<input type="hidden" name="' . $this->name . '" value="' . $this->value . '"/>'; |
67
|
|
|
} |
68
|
|
|
else |
69
|
|
|
// Create a regular list. |
70
|
|
|
{ |
71
|
|
|
$html[] = HtmlSelect::genericlist($options, $this->name, trim($attr), 'value', 'text', $this->value, $this->id); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
return implode($html); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Method to get the field options. |
79
|
|
|
* |
80
|
|
|
* @return array The field option objects. |
81
|
|
|
* |
82
|
|
|
* @since 1.0 |
83
|
|
|
*/ |
84
|
|
|
protected function getOptions() |
85
|
|
|
{ |
86
|
|
|
$options = array(); |
87
|
|
|
|
88
|
|
|
foreach ($this->element->children() as $option) |
89
|
|
|
{ |
90
|
|
|
// Only add <option /> elements. |
91
|
|
|
if ($option->getName() != 'option') |
92
|
|
|
{ |
93
|
|
|
continue; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
// Create a new option object based on the <option /> element. |
97
|
|
|
$tmp = HtmlSelect::option( |
98
|
|
|
(string) $option['value'], |
99
|
|
|
Text::alt(trim((string) $option), preg_replace('/[^a-zA-Z0-9_\-]/', '_', $this->fieldname)), 'value', 'text', |
100
|
|
|
((string) $option['disabled'] == 'true') |
101
|
|
|
); |
102
|
|
|
|
103
|
|
|
// Set some option attributes. |
104
|
|
|
$tmp->class = (string) $option['class']; |
105
|
|
|
|
106
|
|
|
// Set some JavaScript option attributes. |
107
|
|
|
$tmp->onclick = (string) $option['onclick']; |
108
|
|
|
|
109
|
|
|
// Add the option object to the result set. |
110
|
|
|
$options[] = $tmp; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
reset($options); |
114
|
|
|
|
115
|
|
|
return $options; |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.