diff --git a/layouts/joomla/fields/checkboxes.php b/layouts/joomla/fields/checkboxes.php deleted file mode 100644 index 03b06e631dc7a..0000000000000 --- a/layouts/joomla/fields/checkboxes.php +++ /dev/null @@ -1,64 +0,0 @@ -get('classes', array()); -$classes[] = 'checkboxes'; - -/** - * The format of the input tag to be filled in using sprintf. - * %1 - id - * %2 - name - * %3 - value - * %4 = any other attributes - */ -$format = ''; - -$id = $data->get('id', ''); -$name = $data->get('name', ''); -$options = $data->get('options', array()); - -// The alt option for JText::alt -$alt = preg_replace('/[^a-zA-Z0-9_\-]/', '_', $name); -?> - -
get('required') ? 'required aria-required="true"' : '';?> - get('autofocus') ? 'autofocus' : ''; ?>> - - $option) : ?> - - value, $data->get('checkedOptions', array())) ? 'checked' : ''; ?> - - - get('hasValue') && $option->checked) ? 'checked' : $checked; ?> - class) ? 'class="' . $option->class . '"' : ''; ?> - disable) || $data->get('disabled') ? 'disabled' : ''; ?> - - - onclick) ? 'onclick="' . $option->onclick . '"' : ''; ?> - onchange) ? 'onchange="' . $option->onchange . '"' : ''; ?> - - - value, ENT_COMPAT, 'UTF-8'); ?> - - - - -
diff --git a/layouts/joomla/fields/radio.php b/layouts/joomla/fields/radio.php deleted file mode 100644 index 303f2ebcc50e3..0000000000000 --- a/layouts/joomla/fields/radio.php +++ /dev/null @@ -1,66 +0,0 @@ -get('classes', array()); -$classes[] = 'radio'; - -/** - * The format of the input tag to be filled in using sprintf. - * %1 - id - * %2 - name - * %3 - value - * %4 = any other attributes - */ -$format = ''; - -$id = $data->get('id', ''); -$name = $data->get('name', ''); -$value = $data->get('value', ''); -$options = $data->get('options', array()); -$alt = preg_replace('/[^a-zA-Z0-9_\-]/', '_', $name); -?> - -
get('disabled') ? 'disabled' : ''; ?> - get('required') ? 'required aria-required="true"' : ''; ?> - get('autofocus') ? 'autofocus' : ''; ?>> - - - $option) : ?> - - value == $value) ? 'checked="checked"' : ''; ?> - class) ? 'class="' . $option->class . '"' : ''; ?> - disable) || ($data->get('disabled') && !$checked) ? 'disabled' : ''; ?> - - - onclick) ? 'onclick="' . $option->onclick . '"' : ''; ?> - onchange) ? 'onchange="' . $option->onchange . '"' : ''; ?> - - value, ENT_COMPAT, 'UTF-8'); ?> - - - get('required')) : ?> - - - - - - -
diff --git a/layouts/joomla/form/field/checkboxes.php b/layouts/joomla/form/field/checkboxes.php new file mode 100644 index 0000000000000..2aaf099af6b00 --- /dev/null +++ b/layouts/joomla/form/field/checkboxes.php @@ -0,0 +1,89 @@ + section in form XML. + * @var boolean $hidden Is this field hidden in the form? + * @var string $hint Placeholder for the field. + * @var string $id DOM id of the field. + * @var string $label Label of the field. + * @var string $labelclass Classes to apply to the label. + * @var boolean $multiple Does this field support multiple values? + * @var string $name Name of the input field. + * @var string $onchange Onchange attribute for the field. + * @var string $onclick Onclick attribute for the field. + * @var string $pattern Pattern (Reg Ex) of value of the form field. + * @var boolean $readonly Is this field read only? + * @var boolean $repeat Allows extensions to duplicate elements. + * @var boolean $required Is this field required? + * @var integer $size Size attribute of the input. + * @var boolean $spellchec Spellcheck state for the form field. + * @var string $validate Validation rules to apply. + * @var string $value Value attribute of the field. + * @var array $checkedOptions Options that will be set as checked. + * @var boolean $hasValue Has this field a value assigned? + * @var array $options Options available for this field. + */ + +// Including fallback code for HTML5 non supported browsers. +JHtml::_('jquery.framework'); +JHtml::_('script', 'system/html5fallback.js', false, true); + +/** + * The format of the input tag to be filled in using sprintf. + * %1 - id + * %2 - name + * %3 - value + * %4 = any other attributes + */ +$format = ''; + +// The alt option for JText::alt +$alt = preg_replace('/[^a-zA-Z0-9_\-]/', '_', $name); +?> + +
+ > + + $option) : ?> + value, $checkedOptions) ? 'checked' : ''; + + // In case there is no stored value, use the option's default state. + $checked = (!$hasValue && $option->checked) ? 'checked' : $checked; + $optionClass = !empty($option->class) ? 'class="' . $option->class . '"' : ''; + $disabled = !empty($option->disable) || $disabled ? 'disabled' : ''; + + // Initialize some JavaScript option attributes. + $onclick = !empty($option->onclick) ? 'onclick="' . $option->onclick . '"' : ''; + $onchange = !empty($option->onchange) ? 'onchange="' . $option->onchange . '"' : ''; + + $oid = $id . $i; + $value = htmlspecialchars($option->value, ENT_COMPAT, 'UTF-8'); + $attributes = array_filter(array($checked, $optionClass, $disabled, $onchange, $onclick)); + ?> + + + +
diff --git a/layouts/joomla/form/field/radio.php b/layouts/joomla/form/field/radio.php new file mode 100644 index 0000000000000..6962914a5b2b8 --- /dev/null +++ b/layouts/joomla/form/field/radio.php @@ -0,0 +1,89 @@ + section in form XML. + * @var boolean $hidden Is this field hidden in the form? + * @var string $hint Placeholder for the field. + * @var string $id DOM id of the field. + * @var string $label Label of the field. + * @var string $labelclass Classes to apply to the label. + * @var boolean $multiple Does this field support multiple values? + * @var string $name Name of the input field. + * @var string $onchange Onchange attribute for the field. + * @var string $onclick Onclick attribute for the field. + * @var string $pattern Pattern (Reg Ex) of value of the form field. + * @var boolean $readonly Is this field read only? + * @var boolean $repeat Allows extensions to duplicate elements. + * @var boolean $required Is this field required? + * @var integer $size Size attribute of the input. + * @var boolean $spellchec Spellcheck state for the form field. + * @var string $validate Validation rules to apply. + * @var string $value Value attribute of the field. + * @var array $options Options available for this field. + */ + +// Including fallback code for HTML5 non supported browsers. +JHtml::_('jquery.framework'); +JHtml::_('script', 'system/html5fallback.js', false, true); + +/** + * The format of the input tag to be filled in using sprintf. + * %1 - id + * %2 - name + * %3 - value + * %4 = any other attributes + */ +$format = ''; + +$alt = preg_replace('/[^a-zA-Z0-9_\-]/', '_', $name); +?> + +
+ + > + + + $option) : ?> + value == $value) ? 'checked="checked"' : ''; + $optionClass = !empty($option->class) ? 'class="' . $option->class . '"' : ''; + $disabled = !empty($option->disable) || ($disabled && !$checked) ? 'disabled' : ''; + + // Initialize some JavaScript option attributes. + $onclick = !empty($option->onclick) ? 'onclick="' . $option->onclick . '"' : ''; + $onchange = !empty($option->onchange) ? 'onchange="' . $option->onchange . '"' : ''; + $oid = $id . $i; + $ovalue = htmlspecialchars($option->value, ENT_COMPAT, 'UTF-8'); + $attributes = array_filter(array($checked, $optionClass, $disabled, $onchange, $onclick)); + ?> + + + + + + + + +
diff --git a/libraries/joomla/form/field.php b/libraries/joomla/form/field.php index f49fafef02a38..6fa2b8754a08a 100644 --- a/libraries/joomla/form/field.php +++ b/libraries/joomla/form/field.php @@ -302,6 +302,14 @@ abstract class JFormField */ protected static $generated_fieldname = '__field'; + /** + * Name of the layout being used to render the field + * + * @var string + * @since 3.5 + */ + protected $layout; + /** * Layout to render the form field * @@ -373,6 +381,7 @@ public function __get($name) case 'validate': case 'value': case 'class': + case 'layout': case 'labelclass': case 'size': case 'onchange': @@ -433,6 +442,7 @@ public function __set($name, $value) case 'hint': case 'value': case 'labelclass': + case 'layout': case 'onchange': case 'onclick': case 'validate': @@ -581,6 +591,8 @@ public function setup(SimpleXMLElement $element, $value, $group = null) // Set the visibility. $this->hidden = ($this->hidden || (string) $element['type'] == 'hidden'); + $this->layout = !empty($this->element['layout']) ? (string) $this->element['layout'] : $this->layout; + // Add required to class list if field is required. if ($this->required) { @@ -673,7 +685,15 @@ protected function getId($fieldId, $fieldName) * * @since 11.1 */ - abstract protected function getInput(); + protected function getInput() + { + if (empty($this->layout)) + { + throw new UnexpectedValueException(sprintf('%s has no layout assigned.', $this->name)); + } + + return $this->getRenderer($this->layout)->render($this->getLayoutData()); + } /** * Method to get the field title. @@ -712,25 +732,20 @@ protected function getLabel() return ''; } - // Get the label text from the XML element, defaulting to the element name. - $text = $this->element['label'] ? (string) $this->element['label'] : (string) $this->element['name']; - $text = $this->translateLabel ? JText::_($text) : $text; + $data = $this->getLayoutData(); // Forcing the Alias field to display the tip below $position = $this->element['name'] == 'alias' ? ' data-placement="bottom" ' : ''; - $description = ($this->translateDescription && !empty($this->description)) ? JText::_($this->description) : $this->description; - - $displayData = array( - 'text' => $text, - 'description' => $description, - 'for' => $this->id, - 'required' => (bool) $this->required, - 'classes' => explode(' ', $this->labelclass), - 'position' => $position - ); + // Here mainly for B/C with old layouts. This can be done in the layouts directly + $extraData = array( + 'text' => $data['label'], + 'for' => $this->id, + 'classes' => explode(' ', $data['labelclass']), + 'position' => $position + ); - return JLayoutHelper::render($this->renderLabelLayout, $displayData); + return $this->getRenderer($this->renderLabelLayout)->render(array_merge($data, $extraData)); } /** @@ -918,7 +933,13 @@ public function renderField($options = array()) $options['showonEnabled'] = true; } - return JLayoutHelper::render($this->renderLayout, array('input' => $this->getInput(), 'label' => $this->getLabel(), 'options' => $options)); + $data = array( + 'input' => $this->getInput(), + 'label' => $this->getLabel(), + 'options' => $options + ); + + return $this->getRenderer($this->renderLayout)->render($data); } /** @@ -928,31 +949,73 @@ public function renderField($options = array()) * * @since 3.5 */ - protected function getInputLayoutData() + protected function getLayoutData() { + // Label preprocess + $label = $this->element['label'] ? (string) $this->element['label'] : (string) $this->element['name']; + $label = $this->translateLabel ? JText::_($label) : $label; + + // Description preprocess + $description = !empty($this->description) ? $this->description : null; + $description = !empty($description) && $this->translateDescription ? JText::_($description) : $description; + $alt = preg_replace('/[^a-zA-Z0-9_\-]/', '_', $this->fieldname); return array( 'autocomplete' => $this->autocomplete, - 'autofocus' => $this->autofocus, - 'classes' => explode(' ', $this->class), - 'disabled' => $this->disabled, - 'group' => $this->group, - 'hidden' => $this->hidden, - 'hint' => $this->translateHint ? JText::alt($this->hint, $alt) : $this->hint, - 'id' => $this->id, - 'multiple' => $this->multiple, - 'name' => $this->name, - 'onchange' => $this->onchange, - 'onclick' => $this->onclick, - 'pattern' => $this->pattern, - 'readonly' => $this->readonly, - 'repeat' => $this->repeat, - 'required' => $this->required, - 'size' => $this->size, - 'spellcheck' => $this->spellcheck, - 'validate' => $this->validate, - 'value' => $this->value + 'autofocus' => $this->autofocus, + 'class' => $this->class, + 'description' => $description, + 'disabled' => $this->disabled, + 'field' => $this, + 'group' => $this->group, + 'hidden' => $this->hidden, + 'hint' => $this->translateHint ? JText::alt($this->hint, $alt) : $this->hint, + 'id' => $this->id, + 'label' => $label, + 'labelclass' => $this->labelclass, + 'multiple' => $this->multiple, + 'name' => $this->name, + 'onchange' => $this->onchange, + 'onclick' => $this->onclick, + 'pattern' => $this->pattern, + 'readonly' => $this->readonly, + 'repeat' => $this->repeat, + 'required' => (bool) $this->required, + 'size' => $this->size, + 'spellcheck' => $this->spellcheck, + 'validate' => $this->validate, + 'value' => $this->value ); } + + /** + * Get the renderer + * + * @param string $layoutId Id to load + * + * @return JLayout + * + * @since 3.5 + */ + protected function getRenderer($layoutId = 'default') + { + $renderer = new JLayoutFile($layoutId); + + $renderer->setDebug($this->isDebugEnabled()); + + return $renderer; + } + + /** + * Is debug enabled for this field + * + * @return boolean + * + * @since 3.5 + */ + protected function isDebugEnabled() + { + return ($this->getAttribute('debug', 'false') === 'true'); + } } diff --git a/libraries/joomla/form/fields/checkboxes.php b/libraries/joomla/form/fields/checkboxes.php index ecc4ccd985850..07fe77926ee92 100644 --- a/libraries/joomla/form/fields/checkboxes.php +++ b/libraries/joomla/form/fields/checkboxes.php @@ -29,6 +29,14 @@ class JFormFieldCheckboxes extends JFormFieldList */ protected $type = 'Checkboxes'; + /** + * Name of the layout being used to render the field + * + * @var string + * @since 3.5 + */ + protected $layout = 'joomla.form.field.checkboxes'; + /** * Flag to tell the field to always be in multiple values mode. * @@ -89,6 +97,23 @@ public function __set($name, $value) } } + /** + * Method to get the radio button field input markup. + * + * @return string The field input markup. + * + * @since 11.1 + */ + protected function getInput() + { + if (empty($this->layout)) + { + throw new UnexpectedValueException(sprintf('%s has no layout assigned.', $this->name)); + } + + return $this->getRenderer($this->layout)->render($this->getLayoutData()); + } + /** * Method to attach a JForm object to the field. * @@ -115,20 +140,6 @@ public function setup(SimpleXMLElement $element, $value, $group = null) return $return; } - /** - * Method to get the field input markup for check boxes. - * - * @return string The field input markup. - * - * @since 11.1 - */ - protected function getInput() - { - $displayData = $this->getInputLayoutData(); - - return JLayoutHelper::render('joomla.fields.checkboxes', $displayData); - } - /** * Method to get the data to be passed to the layout for rendering. * @@ -136,9 +147,9 @@ protected function getInput() * * @since 3.5 */ - protected function getInputLayoutData() + protected function getLayoutData() { - $displayData = parent::getInputLayoutData(); + $data = parent::getLayoutData(); // True if the field has 'value' set. In other words, it has been stored, don't use the default values. $hasValue = (isset($this->value) && !empty($this->value)); @@ -146,10 +157,12 @@ protected function getInputLayoutData() // If a value has been stored, use it. Otherwise, use the defaults. $checkedOptions = $hasValue ? $this->value : $this->checkedOptions; - $displayData['checkedOptions'] = is_array($checkedOptions) ? $checkedOptions : explode(',', (string) $checkedOptions); - $displayData['hasValue'] = $hasValue; - $displayData['options'] = $this->getOptions(); + $extraData = array( + 'checkedOptions' => is_array($checkedOptions) ? $checkedOptions : explode(',', (string) $checkedOptions), + 'hasValue' => $hasValue, + 'options' => $this->getOptions() + ); - return $displayData; + return array_merge($data, $extraData); } } diff --git a/libraries/joomla/form/fields/radio.php b/libraries/joomla/form/fields/radio.php index 9ead2780c47f5..d59ab1441f3f5 100644 --- a/libraries/joomla/form/fields/radio.php +++ b/libraries/joomla/form/fields/radio.php @@ -28,6 +28,14 @@ class JFormFieldRadio extends JFormFieldList */ protected $type = 'Radio'; + /** + * Name of the layout being used to render the field + * + * @var string + * @since 3.5 + */ + protected $layout = 'joomla.form.field.radio'; + /** * Method to get the radio button field input markup. * @@ -37,9 +45,12 @@ class JFormFieldRadio extends JFormFieldList */ protected function getInput() { - $displayData = $this->getInputLayoutData(); + if (empty($this->layout)) + { + throw new UnexpectedValueException(sprintf('%s has no layout assigned.', $this->name)); + } - return JLayoutHelper::render('joomla.fields.radio', $displayData); + return $this->getRenderer($this->layout)->render($this->getLayoutData()); } /** @@ -47,15 +58,17 @@ protected function getInput() * * @return array * - * @since 3.5 + * @since 3.5 */ - protected function getInputLayoutData() + protected function getLayoutData() { - $displayData = parent::getInputLayoutData(); + $data = parent::getLayoutData(); - $displayData['value'] = (string) $this->value; - $displayData['options'] = $this->getOptions(); + $extraData = array( + 'options' => $this->getOptions(), + 'value' => (string) $this->value + ); - return $displayData; + return array_merge($data, $extraData); } } diff --git a/plugins/editors/codemirror/codemirror.xml b/plugins/editors/codemirror/codemirror.xml index 2143c61b9a2ee..ffbded9116cee 100644 --- a/plugins/editors/codemirror/codemirror.xml +++ b/plugins/editors/codemirror/codemirror.xml @@ -167,7 +167,6 @@