abstract class ElementBase in Form Builder 7.2
Hierarchy
- class \Drupal\form_builder\ElementBase implements ElementInterface
Expanded class hierarchy of ElementBase
2 files declare their use of ElementBase
- Element.php in examples/
src/ Element.php - Element.php in modules/
webform/ src/ Element.php
File
- src/
ElementBase.php, line 5
Namespace
Drupal\form_builderView source
abstract class ElementBase implements ElementInterface {
protected $form;
protected $params;
protected $element;
protected $loader;
public function __construct($form, $params, &$element, $loader) {
$this->form = $form;
$this->params = $params;
$this->element =& $element;
$this->loader = $loader;
}
/**
* Add our pre-render function to the element-array.
*/
protected function addPreRender($element) {
if (isset($element['#type']) && (!isset($element['#pre_render']) || !in_array('form_builder_pre_render', $element['#pre_render']))) {
$element['#pre_render'] = array_merge(element_info_property($element['#type'], '#pre_render', array()), array(
'form_builder_pre_render',
));
}
return $element;
}
/**
* {@inheritdoc}
*/
public function render() {
return $this
->addPreRender($this->element);
}
/**
* {@inheritdoc}
*/
public function getProperties() {
$return = array();
$properties = $this->form
->getProperties();
// Order of the properties is important because of a form-API bug.
// See: https://www.drupal.org/node/990218.
foreach ($this->params['properties'] as $name) {
if (isset($properties[$name])) {
$return[$name] = $properties[$name];
}
}
return $return;
}
/**
* Set the value of a property.
*
* This method must update the $element for rendering as well as for
* later storage.
*
* @param string $property
* Key of the property.
* @param mixed $value
* New value for the property.
*/
protected function setProperty($property, $value) {
// Remove empty properties entirely.
if ($value === '' || is_null($value)) {
unset($this->element['#' . $property]);
}
else {
$this->element['#' . $property] = $value;
}
}
public function getSaveableProperties() {
return $this->params['properties'];
}
/**
* {@inheritdoc}
*/
public function configurationSubmit(&$form, &$form_state) {
// Allow each property to do any necessary submission handling.
foreach ($this
->getProperties() as $property) {
$property
->submit($form, $form_state);
}
// Update the field according to the settings in $form_state['values'].
$saveable = $this
->getSaveableProperties();
foreach ($form_state['values'] as $property => $value) {
if (in_array($property, $saveable, TRUE)) {
$this
->setProperty($property, $value);
}
}
}
/**
* {@inheritdoc}
*/
public function title() {
return $this->element['#title'];
}
public function parentId() {
return $this->element['#form_builder']['parent_id'];
}
public function key() {
return $this->element['#key'];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ElementBase:: |
protected | property | ||
ElementBase:: |
protected | property | ||
ElementBase:: |
protected | property | ||
ElementBase:: |
protected | property | ||
ElementBase:: |
protected | function | Add our pre-render function to the element-array. | |
ElementBase:: |
public | function |
Submit handler for the configuration form. Overrides ElementInterface:: |
1 |
ElementBase:: |
public | function |
Get a list of properties available for this element. Overrides ElementInterface:: |
|
ElementBase:: |
public | function |
Get a list of properties that are supported in any way by this element. Overrides ElementInterface:: |
|
ElementBase:: |
public | function | 1 | |
ElementBase:: |
public | function | ||
ElementBase:: |
public | function |
(Re-)Render an element. Overrides ElementInterface:: |
1 |
ElementBase:: |
protected | function | Set the value of a property. | 1 |
ElementBase:: |
public | function |
Get a human-readable title for this form element. Overrides ElementInterface:: |
1 |
ElementBase:: |
public | function |
Overrides ElementInterface:: |
|
ElementInterface:: |
public | function | Get the configuration form for this element. | 2 |