Source for file field.php
Documentation is available at field.php
* @package Joomla.Platform
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
* Abstract Form Field class for the Joomla Platform.
* @package Joomla.Platform
* The description text for the form field. Usually used in tooltips.
* The hint text for the form field used to display hint inside the field.
* The autocomplete state for the form field. If 'off' element will not be automatically
* The spellcheck state for the form field.
* The autofocus request for the form field. If true element will be automatically
* focused on document load.
* The SimpleXMLElement object of the <field /> XML element that describes the form field.
* The JForm object of the form attached to the form field.
* The form control prefix for field names from the JForm object attached to the form field.
* The hidden state for the form field.
* True to translate the field label string.
* True to translate the field description string.
* True to translate the field hint string.
* The document id for the form field.
* The input for the form field.
* The label for the form field.
* The multiple state for the form field. If true then multiple values are allowed for the
* field. Most often used for list field types.
* Allows extensions to create repeat elements
* The pattern (Reg Ex) of value of the form field.
* The name of the form field.
* The group of the field.
* The required state for the form field. If true then there must be a value for the field to
* The disabled state for the form field. If true then the field will be disabled and user can't
* interact with the field.
* The readonly state for the form field. If true then the field will be readonly.
* The validation method for the form field. This value will determine which method is used
* to validate the value for a field.
* The value of the form field.
* The default value of the form field.
* The size of the form field.
* The class of the form field
* The label's CSS class of the form field
* The javascript onchange of the form field.
* The javascript onclick of the form field.
* The count value for generated name field
protected static $count =
0;
* The string used for generated fields names
protected static $generated_fieldname =
'__field';
* Method to instantiate the form field object.
* @param JForm $form The form to attach to the form field object.
// If there is a form passed into the constructor set the form and form control properties.
if ($form instanceof
JForm)
// Detect the field type if not set
* Method to get certain otherwise inaccessible properties from the form field object.
* @param string $name The property name for which to the the value.
* @return mixed The property value or null.
public function __get($name)
// If the input hasn't yet been generated, generate it.
// If the label hasn't yet been generated, generate it.
* Method to set certain otherwise inaccessible properties of the form field object.
* @param string $name The property name for which to the the value.
* @param mixed $value The value of the property.
public function __set($name, $value)
// Removes spaces from left & right and extra spaces from middle
$this->$name = (string)
$value;
// Allow for field classes to force the multiple values option.
$value = (string)
$value;
$value =
$value ===
'' && isset
($this->forceMultiple) ? (string)
$this->forceMultiple :
$value;
$value = (string)
$value;
$this->$name =
($value ===
'true' ||
$value ===
$name ||
$value ===
'1');
$value = (string)
$value;
$value =
($value ==
'on' ||
$value ==
'') ?
'on' :
$value;
$this->$name =
($value ===
'false' ||
$value ===
'off' ||
$value ===
'0') ?
false :
$value;
case 'translateDescription':
$value = (string)
$value;
$this->$name =
!($value ===
'false' ||
$value ===
'off' ||
$value ===
'0');
$this->$name = (int)
$value;
JLog::add("Cannot access protected / private property $name of " . __CLASS__
);
* Method to attach a JForm object to the field.
* @param JForm $form The JForm object to attach to the form field.
* @return JFormField The form field object so that the method can be used in a chain.
public function setForm(JForm $form)
* Method to attach a JForm object to the field.
* @param SimpleXMLElement $element The SimpleXMLElement object representing the <field /> tag for the form field object.
* @param mixed $value The form field value to validate.
* @param string $group The field name group control value. This acts as as an array container for the field.
* For example if the field has name="foo" and the group value is set to "bar" then the
* full field name would end up being "bar[foo]".
* @return boolean True on success.
public function setup(SimpleXMLElement $element, $value, $group =
null)
// Make sure there is a valid JFormField XML element.
if ((string)
$element->getName() !=
'field')
// Reset the input and label values.
// Set the XML element object.
// Set the group of the field.
'multiple', 'name', 'id', 'hint', 'class', 'description', 'labelClass', 'onchange',
'onclick', 'validate', 'pattern', 'default', 'required',
'disabled', 'readonly', 'autofocus', 'hidden', 'autocomplete', 'spellcheck',
'translateHint', 'translateLabel', 'translateDescription', 'size');
$this->default = isset
($element['value']) ? (string)
$element['value'] :
$this->default;
// Set the field default value.
foreach ($attributes as $attributeName)
$this->__set($attributeName, $element[$attributeName]);
// Allow for repeatable elements
$repeat = (string)
$element['repeat'];
$this->hidden =
($this->hidden || (string)
$element['type'] ==
'hidden');
* Simple method to set the value
* @param mixed $value Value to set
* Method to get the id used for the field input tag.
* @param string $fieldId The field element id.
* @param string $fieldName The field element name.
* @return string The id to be used for the field input tag.
protected function getId($fieldId, $fieldName)
// If there is a form control set for the attached form add it first.
// If the field is in a group add the group control to the field id.
// If we already have an id segment add the group control as another level.
// If we already have an id segment add the field id/name as another level.
$id .=
'_' .
($fieldId ?
$fieldId :
$fieldName);
$id .=
($fieldId ?
$fieldId :
$fieldName);
// Clean up any invalid characters.
// If this is a repeatable element, add the repeat count to the ID
$repeatCounter =
empty($this->form->repeatCounter) ?
0 :
$this->form->repeatCounter;
$id .=
'-' .
$repeatCounter;
* Method to get the field input markup.
* @return string The field input markup.
* Method to get the field title.
* @return string The field title.
// Get the label text from the XML element, defaulting to the element name.
* Method to get the field label markup.
* @return string The field label markup.
// Get the label text from the XML element, defaulting to the element name.
// Build the class for the label.
$class =
!empty($this->description) ?
'hasTooltip' :
'';
$class =
$this->required ==
true ?
$class .
' required' :
$class;
// Add the opening label tag and main attributes attributes.
$label .=
'<label id="' .
$this->id .
'-lbl" for="' .
$this->id .
'" class="' .
$class .
'"';
// If a description is specified, use it to build a tooltip.
JHtml::_('bootstrap.tooltip');
// Add the label text and closing tag.
$label .=
'>' .
$text .
'<span class="star"> *</span></label>';
$label .=
'>' .
$text .
'</label>';
* Method to get the name used for the field input tag.
* @param string $fieldName The field element name.
* @return string The name to be used for the field input tag.
protected function getName($fieldName)
// To support repeated element, extensions can set this in plugin->onRenderSettings
$repeatCounter =
empty($this->form->repeatCounter) ?
0 :
$this->form->repeatCounter;
// If there is a form control set for the attached form add it first.
// If the field is in a group add the group control to the field name.
// If we already have a name segment add the group control as another level.
foreach ($groups as $group)
$name .=
'[' .
$group .
']';
foreach ($groups as $group)
$name .=
'[' .
$group .
']';
// If we already have a name segment add the field name as another level.
$name .=
'[' .
$fieldName .
']';
// If the field should support multiple values add the final array segment.
* Method to get the field name used.
* @param string $fieldName The field element name.
* @return string The field name
self::$count =
self::$count +
1;
return self::$generated_fieldname .
self::$count;
* Method to get an attribute of the field
* @param string $name Name of the attribute to get
* @param mixed $default Optional value to return if attribute not found
* @return mixed Value of the attribute / default
if ($this->element instanceof
SimpleXMLElement)
$attributes =
$this->element->attributes();
// Ensure that the attribute exists
$value =
$attributes->$name;
* Method to get a control group with label and input.
* @return string A string containing the html for the control goup
'<div class="control-group">'
.
'<div class="control-label">' .
$this->getLabel() .
'</div>'
.
'<div class="controls">' .
$this->getInput() .
'</div>'
Documentation generated on Tue, 19 Nov 2013 15:02:57 +0100 by phpDocumentor 1.4.3