138 lines
3.6 KiB
PHP
138 lines
3.6 KiB
PHP
<?php
|
|
/**
|
|
* @package Joomla.Platform
|
|
* @subpackage Form
|
|
*
|
|
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
|
* @license GNU General Public License version 2 or later; see LICENSE
|
|
*/
|
|
|
|
defined('JPATH_PLATFORM') or die;
|
|
|
|
/**
|
|
* Form Field class for the Joomla Platform.
|
|
* Displays options as a list of check boxes.
|
|
* Multiselect may be forced to be true.
|
|
*
|
|
* @package Joomla.Platform
|
|
* @subpackage Form
|
|
* @see JFormFieldCheckbox
|
|
* @since 11.1
|
|
*/
|
|
class JFormFieldCheckboxes extends JFormField
|
|
{
|
|
/**
|
|
* The form field type.
|
|
*
|
|
* @var string
|
|
* @since 11.1
|
|
*/
|
|
protected $type = 'Checkboxes';
|
|
|
|
/**
|
|
* Flag to tell the field to always be in multiple values mode.
|
|
*
|
|
* @var boolean
|
|
* @since 11.1
|
|
*/
|
|
protected $forceMultiple = true;
|
|
|
|
/**
|
|
* Method to get the field input markup for check boxes.
|
|
*
|
|
* @return string The field input markup.
|
|
*
|
|
* @since 11.1
|
|
*/
|
|
protected function getInput()
|
|
{
|
|
$html = array();
|
|
|
|
// Initialize some field attributes.
|
|
$class = $this->element['class'] ? ' class="checkboxes ' . (string) $this->element['class'] . '"' : ' class="checkboxes"';
|
|
$checkedOptions = explode(',', (string) $this->element['checked']);
|
|
|
|
// Start the checkbox field output.
|
|
$html[] = '<fieldset id="' . $this->id . '"' . $class . '>';
|
|
|
|
// Get the field options.
|
|
$options = $this->getOptions();
|
|
|
|
// Build the checkbox field output.
|
|
$html[] = '<ul>';
|
|
foreach ($options as $i => $option)
|
|
{
|
|
// Initialize some option attributes.
|
|
if (!isset($this->value) || empty($this->value))
|
|
{
|
|
$checked = (in_array((string) $option->value, (array) $checkedOptions) ? ' checked="checked"' : '');
|
|
}
|
|
else
|
|
{
|
|
$value = !is_array($this->value) ? explode(',', $this->value) : $this->value;
|
|
$checked = (in_array((string) $option->value, $value) ? ' checked="checked"' : '');
|
|
}
|
|
$class = !empty($option->class) ? ' class="' . $option->class . '"' : '';
|
|
$required = !empty($option->required) ? ' required="required" aria-required="true"' : '';
|
|
$disabled = !empty($option->disable) ? ' disabled="disabled"' : '';
|
|
|
|
// Initialize some JavaScript option attributes.
|
|
$onclick = !empty($option->onclick) ? ' onclick="' . $option->onclick . '"' : '';
|
|
|
|
$html[] = '<li>';
|
|
$html[] = '<input type="checkbox" id="' . $this->id . $i . '" name="' . $this->name . '" value="'
|
|
. htmlspecialchars($option->value, ENT_COMPAT, 'UTF-8') . '"' . $checked . $class . $onclick . $disabled . $required . '/>';
|
|
|
|
$html[] = '<label for="' . $this->id . $i . '"' . $class . '>' . JText::_($option->text) . '</label>';
|
|
$html[] = '</li>';
|
|
}
|
|
$html[] = '</ul>';
|
|
|
|
// End the checkbox field output.
|
|
$html[] = '</fieldset>';
|
|
|
|
return implode($html);
|
|
}
|
|
|
|
/**
|
|
* Method to get the field options.
|
|
*
|
|
* @return array The field option objects.
|
|
*
|
|
* @since 11.1
|
|
*/
|
|
protected function getOptions()
|
|
{
|
|
$options = array();
|
|
|
|
foreach ($this->element->children() as $option)
|
|
{
|
|
|
|
// Only add <option /> elements.
|
|
if ($option->getName() != 'option')
|
|
{
|
|
continue;
|
|
}
|
|
|
|
// Create a new option object based on the <option /> element.
|
|
$tmp = JHtml::_(
|
|
'select.option', (string) $option['value'], trim((string) $option), 'value', 'text',
|
|
((string) $option['disabled'] == 'true')
|
|
);
|
|
|
|
// Set some option attributes.
|
|
$tmp->class = (string) $option['class'];
|
|
|
|
// Set some JavaScript option attributes.
|
|
$tmp->onclick = (string) $option['onclick'];
|
|
|
|
// Add the option object to the result set.
|
|
$options[] = $tmp;
|
|
}
|
|
|
|
reset($options);
|
|
|
|
return $options;
|
|
}
|
|
}
|