protected function loadField($element, $group = null, $value = null)
{
// Make sure there is a valid SimpleXMLElement.
if (!$element instanceof SimpleXMLElement) {
return false;
}
// Get the field type.
$type = $element['type'] ? (string) $element['type'] : 'text';
// Load the JFormField object for the field.
$field = $this->loadFieldType($type);
// If the object could not be loaded, get a text field object.
if ($field === false) {
$field = $this->loadFieldType('text');
}
/*
* Get the value for the form field if not set.
* Default to the translated version of the 'default' attribute
* if 'translate_default' attribute if set to 'true' or '1'
* else the value of the 'default' attribute for the field.
*/
if ($value === null) {
$default = (string) $element['default'];
if (($translate = $element['translate_default']) && ((string) $translate == 'true' || (string) $translate == '1')) {
$lang = JFactory::getLanguage();
if ($lang->hasKey($default)) {
$debug = $lang->setDebug(false);
$default = JText::_($default);
$lang->setDebug($debug);
} else {
$default = JText::_($default);
}
}
$getValueFrom = isset($element['name_from']) ? (string) $element['name_from'] : (string) $element['name'];
$value = $this->getValue($getValueFrom, $group, $default);
}
// Setup the JFormField object.
$field->setForm($this);
if ($field->setup($element, $value, $group)) {
return $field;
} else {
return false;
}
}