/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. defined('JPATH_PLATFORM') or die;
  10. JFormHelper::loadFieldClass('list');
  11. /**
  12. * Form Field class for the Joomla Platform.
  13. * Provides radio button inputs
  14. *
  15. * @link http://www.w3.org/TR/html-markup/command.radio.html#command.radio
  16. * @since 11.1
  17. */
  18. class JFormFieldRadio extends JFormFieldList
  19. {
  20. /**
  21. * The form field type.
  22. *
  23. * @var string
  24. * @since 11.1
  25. */
  26. protected $type = 'Radio';
  27. /**
  28. * Method to get the radio button field input markup.
  29. *
  30. * @return string The field input markup.
  31. *
  32. * @since 11.1
  33. */
  34. protected function getInput()
  35. {
  36. $html = array();
  37. // Initialize some field attributes.
  38. $class = !empty($this->class) ? ' class="radio ' . $this->class . '"' : ' class="radio"';
  39. $required = $this->required ? ' required aria-required="true"' : '';
  40. $autofocus = $this->autofocus ? ' autofocus' : '';
  41. $disabled = $this->disabled ? ' disabled' : '';
  42. $readonly = $this->readonly;
  43. // Start the radio field output.
  44. $html[] = '<fieldset id="' . $this->id . '"' . $class . $required . $autofocus . $disabled . ' >';
  45. // Get the field options.
  46. $options = $this->getOptions();
  47. // Build the radio field output.
  48. foreach ($options as $i => $option)
  49. {
  50. // Initialize some option attributes.
  51. $checked = ((string) $option->value == (string) $this->value) ? ' checked="checked"' : '';
  52. $class = !empty($option->class) ? ' class="' . $option->class . '"' : '';
  53. $disabled = !empty($option->disable) || ($readonly && !$checked);
  54. $disabled = $disabled ? ' disabled' : '';
  55. // Initialize some JavaScript option attributes.
  56. $onclick = !empty($option->onclick) ? ' onclick="' . $option->onclick . '"' : '';
  57. $onchange = !empty($option->onchange) ? ' onchange="' . $option->onchange . '"' : '';
  58. $html[] = '<input type="radio" id="' . $this->id . $i . '" name="' . $this->name . '" value="'
  59. . htmlspecialchars($option->value, ENT_COMPAT, 'UTF-8') . '"' . $checked . $class . $required . $onclick
  60. . $onchange . $disabled . ' />';
  61. $html[] = '<label for="' . $this->id . $i . '"' . $class . ' >'
  62. . JText::alt($option->text, preg_replace('/[^a-zA-Z0-9_\-]/', '_', $this->fieldname)) . '</label>';
  63. $required = '';
  64. }
  65. // End the radio field output.
  66. $html[] = '</fieldset>';
  67. return implode($html);
  68. }
  69. }