API16:JForm/loadFieldType
From Joomla! Documentation
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.
Contents |
Description
Method to load a form field object.
Description:JForm/loadFieldType
Syntax
loadFieldType($type, $new=true)
| Parameter Name | Default Value | Description |
|---|---|---|
| $type | $type The field type. | |
| $new | true | $new Flag to toggle whether we should get a new instance of the object. |
Returns
mixed Field object on success, false otherwise.
Defined in
libraries/joomla/form/form.php
Importing
jimport( 'joomla.form.form' );
Source Body
public function loadFieldType($type, $new = true) { $key = md5($type); $class = 'JFormField'.ucfirst($type); // Return the field object if it already exists and we don't need a new one. if (isset($this->_fieldTypes[$key]) && $new === false) { return $this->_fieldTypes[$key]; } if (!class_exists('JFormField')) { jimport('joomla.form.formfield'); } if (!class_exists('JFormFieldList')) { require_once dirname(__FILE__).'/fields/list.php'; } if (!class_exists($class)) { $paths = self::addFieldPath(); // If the type is complex, add the base type to the paths. if ($pos = strpos($type, '_')) { // Add the complex type prefix to the paths. for ($i = 0, $n = count($paths); $i < $n; $i++) { // Derive the new path. $path = $paths[$i].DS.strtolower(substr($type, 0, $pos)); // If the path does not exist, add it. if (!in_array($path, $paths)) { array_unshift($paths, $path); } } // Break off the end of the complex type. $type = substr($type, $pos+1); } // Try to find the field file. jimport('joomla.filesystem.path'); if ($file = JPath::find($paths, strtolower($type).'.php')) { require_once $file; } else { return false; } // Check once and for all if the class exists. if (!class_exists($class)) { return false; } } // Instantiate a new field object. $this->_fieldTypes[$key] = new $class($this); return $this->_fieldTypes[$key]; }
[Edit See Also] SeeAlso:JForm/loadFieldType
Examples
<CodeExamplesForm />
