FOF30\Form\Form::loadField PHP Method

loadField() protected method

Method to load, setup and return a JFormField object based on field data.
Since: 11.1
protected loadField ( string $element, string $group = null, mixed $value = null ) : mixed
$element string The XML element object representation of the form field.
$group string The optional dot-separated form group path on which to find the field.
$value mixed The optional value to use as the default for the field.
return mixed The JFormField object for the field or boolean false on error.
    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;
        }
    }