PHP Class FOF30\Form\Form

Since: 2.0
Inheritance: extends JFor\JForm
Show file Open project: akeeba/fof Class Usage Examples

Protected Properties

Property Type Description
$container FOF30\Container\Container The Container this form belongs to
$entities array Prototypes for all fields and rules are here. Array's structure: entities: {ENTITY_NAME}: {KEY}: {OBJECT}
$model FOF30\Model\DataModel The model attached to this view
$view FOF30\View\DataView\DataViewInterface The view used to render this form

Public Methods

Method Description
__construct ( Container $container, string $name, array $options = [] ) Method to instantiate the form object.
addFieldPath ( string $new = null ) : void WARNING: THIS IS IGNORED IN FOF3!
addFormPath ( string $new = null ) : void WARNING: THIS IS IGNORED IN FOF3!
addHeaderPath ( string $new = null ) : void WARNING: THIS IS IGNORED IN FOF3!
addRulePath ( string $new = null ) : void WARNING: THIS IS IGNORED IN FOF3!
bind ( mixed $data ) : boolean Method to bind data to the form.
getAttribute ( string $attribute, mixed $default = null ) : mixed Returns the value of an attribute of the form itself
getContainer ( ) : Container Get a reference to the form's Container
getData ( ) : JRegistry Returns a reference to the protected $data object, allowing direct access to and manipulation of the form's data.
getHeader ( string $name, string $group = null, mixed $value = null ) : FOF30\Form\HeaderInterface | boolean Method to get a header field represented as a HeaderInterface object.
getHeaderset ( ) : array Method to get an array of FormHeader objects in the headerset.
getModel ( ) : DataModel Returns the DataModel attached to this form
getView ( ) : FOF30\View\DataView\DataViewInterface Returns the DataViewInterface attached to this form
loadCSSFiles ( ) : void Loads the CSS files defined in the form, based on its cssfiles attribute
loadClass ( string $entity, string $type ) : mixed Load a class for one of the form's entities of a particular type.
loadFile ( string $file, boolean $reset = true, boolean $xpath = false ) : boolean Method to load the form description from an XML file.
loadJSFiles ( ) : void Loads the Javascript files defined in the form, based on its jsfiles attribute
removeHeader ( string $name, string $group = null ) : boolean Method to remove a header from the form definition.
setContainer ( Container $container ) Set the form's Container
setModel ( DataModel &$model ) : void Attaches a DataModel to this form
setView ( FOF30\View\DataView\DataViewInterface &$view ) : void Attaches a DataViewInterface to this form

Protected Methods

Method Description
bindLevel ( string $group, mixed $data ) : void Method to bind data to the form for the group level.
findField ( string $name, string $group = null ) : mixed Method to get a form field represented as an XML element object.
findHeader ( string $name, string $group = null ) : mixed Method to get a header field represented as an XML element object.
findHeadersByGroup ( mixed $group = null, boolean $nested = false ) : SimpleXMLElement | boolean Method to get an array of
elements from the form XML document which are in a control group by name.
loadField ( string $element, string $group = null, mixed $value = null ) : mixed Method to load, setup and return a JFormField object based on field data.
loadFieldType ( string $type, boolean $new = true ) : FOF30\Form\FieldInterface | boolean Proxy for {@link Helper::loadFieldType()}.
loadHeader ( string $element, string $group = null ) : FOF30\Form\HeaderInterface | boolean Method to load, setup and return a HeaderInterface object based on field data.
loadHeaderType ( string $type, boolean $new = true ) : FOF30\Form\HeaderInterface | boolean Proxy for {@link Helper::loadHeaderType()}.
loadRuleType ( string $type, boolean $new = true ) : JFormRule | boolean Proxy for {@link Helper::loadRuleType()}.
loadType ( string $entity, string $type, boolean $new = true ) : mixed Method to load a form entity object given a type.
modelToBindSource ( DataModel $model, integer $maxLevel = 1, array $modelsProcessed = [] ) : array Converts a DataModel into data suitable for use with the form. The difference to the Model's getData() method is that we process hasOne and belongsTo relations. This is a recursive function which will be called at most $maxLevel deep. You can set this in the form XML file, in the relation_depth attribute.

Method Details

__construct() public method

Method to instantiate the form object.
public __construct ( Container $container, string $name, array $options = [] )
$container FOF30\Container\Container The component Container where this form belongs to
$name string The name of the form.
$options array An array of form options.

addFieldPath() public static method

WARNING: THIS IS IGNORED IN FOF3!
Deprecation: 3.0
public static addFieldPath ( string $new = null ) : void
$new string IGNORED!
return void

addFormPath() public static method

WARNING: THIS IS IGNORED IN FOF3!
Deprecation: 3.0
public static addFormPath ( string $new = null ) : void
$new string IGNORED!
return void

addHeaderPath() public static method

WARNING: THIS IS IGNORED IN FOF3!
Deprecation: 3.0
public static addHeaderPath ( string $new = null ) : void
$new string IGNORED!
return void

addRulePath() public static method

WARNING: THIS IS IGNORED IN FOF3!
Deprecation: 3.0
public static addRulePath ( string $new = null ) : void
$new string IGNORED!
return void

bind() public method

Method to bind data to the form.
Since: 11.1
public bind ( mixed $data ) : boolean
$data mixed An array or object of data to bind to the form.
return boolean True on success.

bindLevel() protected method

Method to bind data to the form for the group level.
Since: 11.1
protected bindLevel ( string $group, mixed $data ) : void
$group string The dot-separated form group path on which to bind the data.
$data mixed An array or object of data to bind to the form for the group level.
return void

findField() protected method

Method to get a form field represented as an XML element object.
Since: 11.1
protected findField ( string $name, string $group = null ) : mixed
$name string The name of the form field.
$group string The optional dot-separated form group path on which to find the field.
return mixed The XML element object for the field or boolean false on error.

findHeader() protected method

Method to get a header field represented as an XML element object.
Since: 2.0
protected findHeader ( string $name, string $group = null ) : mixed
$name string The name of the form field.
$group string The optional dot-separated form group path on which to find the field.
return mixed The XML element object for the field or boolean false on error.

findHeadersByGroup() protected method

Method to get an array of
elements from the form XML document which are in a control group by name.
Since: 2.0
protected findHeadersByGroup ( mixed $group = null, boolean $nested = false ) : SimpleXMLElement | boolean
$group mixed The optional dot-separated form group path on which to find the fields. Null will return all fields. False will return fields not in a group.
$nested boolean True to also include fields in nested groups that are inside of the group for which to find fields.
return SimpleXMLElement | boolean Boolean false on error or array of SimpleXMLElement objects.

getAttribute() public method

Returns the value of an attribute of the form itself
Since: 2.0
public getAttribute ( string $attribute, mixed $default = null ) : mixed
$attribute string The name of the attribute
$default mixed Optional default value to return
return mixed

getContainer() public method

Get a reference to the form's Container
public getContainer ( ) : Container
return FOF30\Container\Container

getData() public method

Returns a reference to the protected $data object, allowing direct access to and manipulation of the form's data.
Since: 2.0
public getData ( ) : JRegistry
return JRegistry The form's data registry

getHeader() public method

Method to get a header field represented as a HeaderInterface object.
Since: 2.0
public getHeader ( string $name, string $group = null, mixed $value = null ) : FOF30\Form\HeaderInterface | boolean
$name string The name of the header 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. (DEPRECATED)
return FOF30\Form\HeaderInterface | boolean The HeaderInterface object for the field or boolean false on error.

getHeaderset() public method

Method to get an array of FormHeader objects in the headerset.
Since: 2.0
public getHeaderset ( ) : array
return array The array of HeaderInterface objects in the headerset.

getModel() public method

Returns the DataModel attached to this form
public getModel ( ) : DataModel
return FOF30\Model\DataModel

getView() public method

Returns the DataViewInterface attached to this form
public getView ( ) : FOF30\View\DataView\DataViewInterface
return FOF30\View\DataView\DataViewInterface

loadCSSFiles() public method

Loads the CSS files defined in the form, based on its cssfiles attribute
Since: 2.0
public loadCSSFiles ( ) : void
return void

loadClass() public method

Currently, it makes sense to use this method for the "field" and "rule" entities (but you can support more entities in your subclass).
Since: 2.0
public loadClass ( string $entity, string $type ) : mixed
$entity string One of the form entities (field, header or rule).
$type string Type of an entity.
return mixed Class name on success or false otherwise.

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.

loadFieldType() protected method

Proxy for {@link Helper::loadFieldType()}.
Since: 2.0
protected loadFieldType ( string $type, boolean $new = true ) : FOF30\Form\FieldInterface | boolean
$type string The field type.
$new boolean Flag to toggle whether we should get a new instance of the object.
return FOF30\Form\FieldInterface | boolean FieldInterface object on success, false otherwise.

loadFile() public method

The reset option works on a group basis. If the XML file references groups that have already been created they will be replaced with the fields in the new XML file unless the $reset parameter has been set to false.
public loadFile ( string $file, boolean $reset = true, boolean $xpath = false ) : boolean
$file string The filesystem path of an XML file.
$reset boolean Flag to toggle whether form fields should be replaced if a field already exists with the same group/name.
$xpath boolean An optional xpath to search for the fields.
return boolean True on success, false otherwise.

loadHeader() protected method

Method to load, setup and return a HeaderInterface object based on field data.
Since: 2.0
protected loadHeader ( string $element, string $group = null ) : FOF30\Form\HeaderInterface | boolean
$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.
return FOF30\Form\HeaderInterface | boolean The HeaderInterface object for the field or boolean false on error.

loadHeaderType() protected method

Proxy for {@link Helper::loadHeaderType()}.
Since: 2.0
protected loadHeaderType ( string $type, boolean $new = true ) : FOF30\Form\HeaderInterface | boolean
$type string The field type.
$new boolean Flag to toggle whether we should get a new instance of the object.
return FOF30\Form\HeaderInterface | boolean HeaderInterface object on success, false otherwise.

loadJSFiles() public method

Loads the Javascript files defined in the form, based on its jsfiles attribute
Since: 2.0
public loadJSFiles ( ) : void
return void

loadRuleType() protected method

Proxy for {@link Helper::loadRuleType()}.
See also: Helper::loadRuleType()
Since: 2.0
protected loadRuleType ( string $type, boolean $new = true ) : JFormRule | boolean
$type string The rule type.
$new boolean Flag to toggle whether we should get a new instance of the object.
return JFormRule | boolean JFormRule object on success, false otherwise.

loadType() protected method

Each type is loaded only once and then used as a prototype for other objects of same type. Please, use this method only with those entities which support types (forms don't support them).
protected loadType ( string $entity, string $type, boolean $new = true ) : mixed
$entity string The entity.
$type string The entity type.
$new boolean Flag to toggle whether we should get a new instance of the object.
return mixed Entity object on success, false otherwise.

modelToBindSource() protected method

The $modelsProcessed array which is passed in successive recursions lets us prevent pointless Inception-style recursions, e.g. Model A is related to Model B is related to Model C is related to Model A. You clearly don't care to see a.b.c.a.b in the results. You just want a.b.c. Obviously c is indirectly related to a because that's where you began the recursion anyway.
protected modelToBindSource ( DataModel $model, integer $maxLevel = 1, array $modelsProcessed = [] ) : array
$model FOF30\Model\DataModel The item to dump its contents into an array
$maxLevel integer Maximum nesting level of relations to process. Default: 1.
$modelsProcessed array Array of the fully qualified model class names already processed.
return array

removeHeader() public method

Method to remove a header from the form definition.
public removeHeader ( string $name, string $group = null ) : boolean
$name string The name of the form field for which remove.
$group string The optional dot-separated form group path on which to find the field.
return boolean True on success, false otherwise.

setContainer() public method

Set the form's Container
public setContainer ( Container $container )
$container FOF30\Container\Container

setModel() public method

Attaches a DataModel to this form
public setModel ( DataModel &$model ) : void
$model FOF30\Model\DataModel
return void

setView() public method

Attaches a DataViewInterface to this form
public setView ( FOF30\View\DataView\DataViewInterface &$view ) : void
$view FOF30\View\DataView\DataViewInterface
return void

Property Details

$container protected property

The Container this form belongs to
protected Container,FOF30\Container $container
return FOF30\Container\Container

$entities protected property

Prototypes for all fields and rules are here. Array's structure: entities: {ENTITY_NAME}: {KEY}: {OBJECT}
protected array $entities
return array

$model protected property

The model attached to this view
protected DataModel,FOF30\Model $model
return FOF30\Model\DataModel

$view protected property

The view used to render this form
protected DataViewInterface,FOF30\View\DataView $view
return FOF30\View\DataView\DataViewInterface