PageRenderTime 24ms CodeModel.GetById 18ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/libraries/joomla/form/fields/radio.php

https://gitlab.com/vitaliylukin91/lavka
PHP | 85 lines | 35 code | 16 blank | 34 comment | 3 complexity | 8dc672ce52fe3212773abaa213f0036b MD5 | raw file
 1<?php
 2/**
 3 * @package     Joomla.Platform
 4 * @subpackage  Form
 5 *
 6 * @copyright   Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
 7 * @license     GNU General Public License version 2 or later; see LICENSE
 8 */
 9
10defined('JPATH_PLATFORM') or die;
11
12JFormHelper::loadFieldClass('list');
13
14/**
15 * Form Field class for the Joomla Platform.
16 * Provides radio button inputs
17 *
18 * @link   http://www.w3.org/TR/html-markup/command.radio.html#command.radio
19 * @since  11.1
20 */
21class JFormFieldRadio extends JFormFieldList
22{
23	/**
24	 * The form field type.
25	 *
26	 * @var    string
27	 * @since  11.1
28	 */
29	protected $type = 'Radio';
30
31	/**
32	 * Method to get the radio button field input markup.
33	 *
34	 * @return  string  The field input markup.
35	 *
36	 * @since   11.1
37	 */
38	protected function getInput()
39	{
40		$html = array();
41
42		// Initialize some field attributes.
43		$class     = !empty($this->class) ? ' class="radio ' . $this->class . '"' : ' class="radio"';
44		$required  = $this->required ? ' required aria-required="true"' : '';
45		$autofocus = $this->autofocus ? ' autofocus' : '';
46		$disabled  = $this->disabled ? ' disabled' : '';
47		$readonly  = $this->readonly;
48
49		// Start the radio field output.
50		$html[] = '<fieldset id="' . $this->id . '"' . $class . $required . $autofocus . $disabled . ' >';
51
52		// Get the field options.
53		$options = $this->getOptions();
54
55		// Build the radio field output.
56		foreach ($options as $i => $option)
57		{
58			// Initialize some option attributes.
59			$checked = ((string) $option->value == (string) $this->value) ? ' checked="checked"' : '';
60			$class = !empty($option->class) ? ' class="' . $option->class . '"' : '';
61
62			$disabled = !empty($option->disable) || ($readonly && !$checked);
63
64			$disabled = $disabled ? ' disabled' : '';
65
66			// Initialize some JavaScript option attributes.
67			$onclick = !empty($option->onclick) ? ' onclick="' . $option->onclick . '"' : '';
68			$onchange = !empty($option->onchange) ? ' onchange="' . $option->onchange . '"' : '';
69
70			$html[] = '<input type="radio" id="' . $this->id . $i . '" name="' . $this->name . '" value="'
71				. htmlspecialchars($option->value, ENT_COMPAT, 'UTF-8') . '"' . $checked . $class . $required . $onclick
72				. $onchange . $disabled . ' />';
73
74			$html[] = '<label for="' . $this->id . $i . '"' . $class . ' >'
75				. JText::alt($option->text, preg_replace('/[^a-zA-Z0-9_\-]/', '_', $this->fieldname)) . '</label>';
76
77			$required = '';
78		}
79
80		// End the radio field output.
81		$html[] = '</fieldset>';
82
83		return implode($html);
84	}
85}