JForm/loadFieldType: Difference between revisions
From Joomla! Documentation
New page: ===Description===
Method to load a form field object.
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>Edit Descripton<nowiki>]<... |
m preparing for archive only |
||
| (2 intermediate revisions by the same user not shown) | |||
| Line 2: | Line 2: | ||
Method to load a form field object. | Method to load a form field object. | ||
<! removed transcluded page call, red link never existed > | |||
===Syntax=== | ===Syntax=== | ||
| Line 95: | Line 93: | ||
</source> | </source> | ||
<! removed transcluded page call, red link never existed > | |||
< | |||
===Examples=== | ===Examples=== | ||
=== Code Examples === | |||
<dpl> | <dpl> | ||
noresultsheader=\n | noresultsheader=\n | ||
category=loadFieldType | category=loadFieldType | ||
category=JForm | category=JForm | ||
namespace=CodeExample | |||
category=MethodExample | category=MethodExample | ||
include=* | include=* | ||
format= ,,, | format= ,,, | ||
</dpl> | </dpl> | ||
[[Category:Archived pages API16]] | |||
Latest revision as of 01:41, 25 March 2017
Description
Method to load a form field object.
<! removed transcluded page call, red link never existed >
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];
}
<! removed transcluded page call, red link never existed >
Examples
Code Examples