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 stdClass; |
12
|
|
|
use Joomla\Language\Text; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Form Field class for the Joomla Framework. |
16
|
|
|
* Provides radio button inputs |
17
|
|
|
* |
18
|
|
|
* @link http://www.w3.org/TR/html-markup/command.radio.html#command.radio |
19
|
|
|
* @since 1.0 |
20
|
|
|
* @deprecated The joomla/form package is deprecated |
21
|
|
|
*/ |
22
|
|
|
class Field_Radio extends Field |
|
|
|
|
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* The form field type. |
26
|
|
|
* |
27
|
|
|
* @var string |
28
|
|
|
* @since 1.0 |
29
|
|
|
*/ |
30
|
|
|
protected $type = 'Radio'; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Method to get the radio button field input markup. |
34
|
|
|
* |
35
|
|
|
* @return string The field input markup. |
36
|
|
|
* |
37
|
|
|
* @since 1.0 |
38
|
|
|
*/ |
39
|
|
|
protected function getInput() |
40
|
|
|
{ |
41
|
|
|
$html = array(); |
42
|
|
|
|
43
|
|
|
// Initialize some field attributes. |
44
|
|
|
$class = $this->element['class'] ? ' class="radio ' . (string) $this->element['class'] . '"' : ' class="radio"'; |
45
|
|
|
|
46
|
|
|
// Start the radio field output. |
47
|
|
|
$html[] = '<fieldset id="' . $this->id . '"' . $class . '>'; |
48
|
|
|
|
49
|
|
|
// Get the field options. |
50
|
|
|
$options = $this->getOptions(); |
51
|
|
|
|
52
|
|
|
// Build the radio field output. |
53
|
|
|
foreach ($options as $i => $option) |
54
|
|
|
{ |
55
|
|
|
// Initialize some option attributes. |
56
|
|
|
$checked = ((string) $option->value == (string) $this->value) ? ' checked="checked"' : ''; |
57
|
|
|
$class = !empty($option->class) ? ' class="' . $option->class . '"' : ''; |
58
|
|
|
$disabled = !empty($option->disable) ? ' disabled="disabled"' : ''; |
59
|
|
|
|
60
|
|
|
// Initialize some JavaScript option attributes. |
61
|
|
|
$onclick = !empty($option->onclick) ? ' onclick="' . $option->onclick . '"' : ''; |
62
|
|
|
|
63
|
|
|
$html[] = '<input type="radio" id="' . $this->id . $i . '" name="' . $this->name . '"' . ' value="' |
64
|
|
|
. htmlspecialchars($option->value, ENT_COMPAT, 'UTF-8') . '"' . $checked . $class . $onclick . $disabled . '/>'; |
65
|
|
|
|
66
|
|
|
$html[] = '<label for="' . $this->id . $i . '"' . $class . '>' |
67
|
|
|
. Text::alt($option->text, preg_replace('/[^a-zA-Z0-9_\-]/', '_', $this->fieldname)) . '</label>'; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
// End the radio field output. |
71
|
|
|
$html[] = '</fieldset>'; |
72
|
|
|
|
73
|
|
|
return implode($html); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Method to get the field options for radio buttons. |
78
|
|
|
* |
79
|
|
|
* @return array The field option objects. |
80
|
|
|
* |
81
|
|
|
* @since 1.0 |
82
|
|
|
*/ |
83
|
|
|
protected function getOptions() |
84
|
|
|
{ |
85
|
|
|
$options = array(); |
86
|
|
|
|
87
|
|
|
foreach ($this->element->children() as $option) |
88
|
|
|
{ |
89
|
|
|
// Only add <option /> elements. |
90
|
|
|
if ($option->getName() != 'option') |
91
|
|
|
{ |
92
|
|
|
continue; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
// Set up option elements. |
96
|
|
|
$tmp = new stdClass; |
97
|
|
|
$tmp->value = (string) $option['value']; |
98
|
|
|
$tmp->text = trim((string) $option); |
99
|
|
|
$tmp->disable = ((string) $option['disabled'] == 'true'); |
100
|
|
|
$tmp->class = (string) $option['class']; |
101
|
|
|
$tmp->onclick = (string) $option['onclick']; |
102
|
|
|
|
103
|
|
|
// Add the option object to the result set. |
104
|
|
|
$options[] = $tmp; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
reset($options); |
108
|
|
|
|
109
|
|
|
return $options; |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
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.