class RulesFormsElementWrapper in Rules Forms Support 7.2
Wrapper class for form element arrays.
Hierarchy
- class \EntityMetadataWrapper
- class \EntityStructureWrapper implements \IteratorAggregate
- class \RulesFormsStructureWrapper
- class \RulesFormsElementWrapper
- class \RulesFormsStructureWrapper
- class \EntityStructureWrapper implements \IteratorAggregate
Expanded class hierarchy of RulesFormsElementWrapper
1 string reference to 'RulesFormsElementWrapper'
- rules_forms_rules_data_info in ./
rules_forms.rules.inc - Implements hook_rules_data_info().
File
- includes/
rules_forms.wrapper.inc, line 85 - Manages and Process Form structure.
View source
class RulesFormsElementWrapper extends RulesFormsStructureWrapper {
/**
* {@inheritdoc}
*/
public function __construct($type, $data = NULL, $info = array()) {
$info += array(
'element info' => array(),
);
$info['element info'] += array(
'data type' => 'text',
);
parent::__construct($type, $data, $info);
}
/**
* Magic method: Determine if a form element attribute is set.
*/
public function __isset($name) {
return isset($this->data[$name]);
}
/**
* Magic method: Unset a form element attribute.
*/
public function __unset($name) {
unset($this->data[$name]);
}
/**
* Returns element info as defined in element property info.
*
* @param string $name
* An optional name of a key to return.
*
* @return mixed
* An array of element info, or a specific property if $name is defined.
*/
public function getElementInfo($name = NULL) {
$info = $this
->info();
if (isset($info['element info'])) {
if (isset($name)) {
return isset($info['element info'][$name]) ? $info['element info'][$name] : NULL;
}
return $info['element info'];
}
return array();
}
/**
* Returns the data type of the form element.
*/
public function getElementDataType() {
return $this->info['element info']['data type'];
}
/**
* Returns the form element name for use in form_set_error().
*
* @return string
* The form element name as required by form_set_error().
*
* @throws EntityMetadataWrapperException
* The form element 'name' was not found.
*/
public function getElementName() {
if (!isset($this->info['element info']['name'])) {
throw new EntityMetadataWrapperException('Unknown form element name for ' . check_plain($this->info['name']) . '.');
}
return $this->info['element info']['name'];
}
/**
* Returns an element key.
*
* @param string $name
* The name of the element key to return.
*
* @return string|false
* The indicated key or FALSE if none was found.
*/
public function getElementKey($name) {
if (isset($this->info['element info']['keys'][$name])) {
return $this->info['element info']['keys'][$name];
}
return FALSE;
}
/**
* Returns the current value of the form element.
*
* Value is taken either from #value or #default_value. If neither is set we
* use the 'empty value' key.
*
* @return mixed
* The element value retrieved from defined keys. If neither the value or
* default value is defined, the empty value will be returned.
*
* @throws EntityMetadataWrapperException
* The form element does not contain a value.
*/
public function getElementValue() {
if ($this->info['element info']['data type'] === FALSE) {
throw new EntityMetadataWrapperException('Form element ' . check_plain($this->info['name']) . ' does not contain a value.');
}
$data = $this
->value();
$value_key = $this
->getElementKey('value');
if ($value_key && isset($data[$value_key])) {
return $data[$value_key];
}
elseif ($default_value_key = $this
->getElementKey('default_value') && isset($data[$default_value_key])) {
return $data[$default_value_key];
}
return $this
->getElementEmptyValue();
}
/**
* Sets the value of the form element.
*
* @param mixed $value
* The value to set.
*
* @return RulesFormsElementWrapper
* The called object.
*
* @throws EntityMetadataWrapperException
* The form element does not support a value.
*/
public function setElementValue($value) {
if ($this->info['element info']['data type'] == FALSE || ($value_key = $this
->getElementKey('value') === FALSE)) {
throw new EntityMetadataWrapperException('Form element ' . check_plain($this->info['name']) . ' does not support a value.');
}
else {
$this
->get($value_key)
->set($value);
}
return $this;
}
/**
* Sets the default value of the form element.
*
* @param mixed $value
* The value to set.
*
* @return RulesFormsElementWrapper
* The called object.
*
* @throws EntityMetadataWrapperException
* The form element does not support a default value.
*/
public function setElementDefaultValue($value) {
if ($this->info['element info']['data type'] == FALSE || ($default_value_key = $this
->getElementKey('default_value') === FALSE)) {
throw new EntityMetadataWrapperException('Form element ' . check_plain($this->info['name']) . ' does not support a default value.');
}
else {
$this
->get($default_value_key)
->set($value);
}
return $this;
}
/**
* Returns the form element value when #value and #default_value are not set.
*/
public function getElementEmptyValue() {
return $this->info['element info']['empty'];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
EntityMetadataWrapper:: |
protected | property | ||
EntityMetadataWrapper:: |
protected | property | ||
EntityMetadataWrapper:: |
protected | property | ||
EntityMetadataWrapper:: |
protected | property | 1 | |
EntityMetadataWrapper:: |
public | function | Determines whether the given user has access to view or edit this property. Apart from relying on access metadata of properties, this takes into account information about entity level access, if available: | 1 |
EntityMetadataWrapper:: |
protected | function | Returns whether data is available to work with. | |
EntityMetadataWrapper:: |
public | function | Returns a string to use to identify this wrapper in error messages. | 1 |
EntityMetadataWrapper:: |
public | function | Gets info about the wrapped data. | |
EntityMetadataWrapper:: |
public | function | Returns the label for the currently set property value if there is one available, i.e. if an options list has been specified. | 2 |
EntityMetadataWrapper:: |
public | function | Returns the options list specifying possible values for the property, if defined. | |
EntityMetadataWrapper:: |
public | function | Returns the raw, unprocessed data. Most times this is the same as returned by value(), however for already processed and sanitized textual data, this will return the unprocessed data in contrast to value(). | |
EntityMetadataWrapper:: |
public | function | Set a new data value. | 2 |
EntityMetadataWrapper:: |
public | function | Gets the (entity)type of the wrapped data. | 1 |
EntityMetadataWrapper:: |
protected | function | Updates the parent data structure of a data property with the latest data value. | |
EntityMetadataWrapper:: |
public | function | Returns whether $value is a valid value to set. | 1 |
EntityMetadataWrapper:: |
public | function | Returns the wrapped data. If no options are given the data is returned as described in the info. | 3 |
EntityMetadataWrapper:: |
public | function | ||
EntityStructureWrapper:: |
protected | property | ||
EntityStructureWrapper:: |
protected | property | ||
EntityStructureWrapper:: |
protected | property | ||
EntityStructureWrapper:: |
public | function |
Clears the data value and the wrapper cache. Overrides EntityMetadataWrapper:: |
1 |
EntityStructureWrapper:: |
public | function | Returns the identifier of the data structure. If there is none, NULL is returned. | 1 |
EntityStructureWrapper:: |
public | function | ||
EntityStructureWrapper:: |
public | function | Gets the info about the given property. | |
EntityStructureWrapper:: |
public | function | Gets the language used for retrieving properties. | |
EntityStructureWrapper:: |
protected | function | Gets the raw value of a property. | |
EntityStructureWrapper:: |
protected | function | Gets the value of a property. | |
EntityStructureWrapper:: |
public | function | Sets a new language to use for retrieving properties. | |
EntityStructureWrapper:: |
protected | function | ||
EntityStructureWrapper:: |
public | function | Returns a reference on the property info. | |
EntityStructureWrapper:: |
protected | function | Sets a property. | |
EntityStructureWrapper:: |
protected | function | May be used to lazy-load additional info about the data, depending on the concrete passed data. | 1 |
EntityStructureWrapper:: |
public | function | Magic method: Get a wrapper for a property. | |
EntityStructureWrapper:: |
public | function | Magic method: Set a property. | |
EntityStructureWrapper:: |
public | function |
Prepare for serializiation. Overrides EntityMetadataWrapper:: |
1 |
RulesFormsElementWrapper:: |
public | function | Returns the data type of the form element. | |
RulesFormsElementWrapper:: |
public | function | Returns the form element value when #value and #default_value are not set. | |
RulesFormsElementWrapper:: |
public | function | Returns element info as defined in element property info. | |
RulesFormsElementWrapper:: |
public | function | Returns an element key. | |
RulesFormsElementWrapper:: |
public | function | Returns the form element name for use in form_set_error(). | |
RulesFormsElementWrapper:: |
public | function | Returns the current value of the form element. | |
RulesFormsElementWrapper:: |
public | function | Sets the default value of the form element. | |
RulesFormsElementWrapper:: |
public | function | Sets the value of the form element. | |
RulesFormsElementWrapper:: |
public | function |
Construct a new EntityStructureWrapper object. Overrides EntityStructureWrapper:: |
|
RulesFormsElementWrapper:: |
public | function |
Magic method: Determine if a form element attribute is set. Overrides EntityStructureWrapper:: |
|
RulesFormsElementWrapper:: |
public | function | Magic method: Unset a form element attribute. | |
RulesFormsStructureWrapper:: |
public | function |
Overrides EntityStructureWrapper::get() to ensure data is properly wrapped. Overrides EntityStructureWrapper:: |