trait FormStateValuesTrait
Same name in other branches
- 9 core/lib/Drupal/Core/Form/FormStateValuesTrait.php \Drupal\Core\Form\FormStateValuesTrait
- 8.9.x core/lib/Drupal/Core/Form/FormStateValuesTrait.php \Drupal\Core\Form\FormStateValuesTrait
- 11.x core/lib/Drupal/Core/Form/FormStateValuesTrait.php \Drupal\Core\Form\FormStateValuesTrait
Provides methods to manage form state values.
Hierarchy
- trait \Drupal\Core\Form\FormStateValuesTrait
See also
\Drupal\Core\Form\FormStateInterface
Related topics
1 file declares its use of FormStateValuesTrait
- FormStateValuesTraitTest.php in core/
tests/ Drupal/ Tests/ Core/ Form/ FormStateValuesTraitTest.php
File
-
core/
lib/ Drupal/ Core/ Form/ FormStateValuesTrait.php, line 14
Namespace
Drupal\Core\FormView source
trait FormStateValuesTrait {
/**
* Implements \Drupal\Core\Form\FormStateInterface::getValues()
*/
public abstract function &getValues();
/**
* Implements \Drupal\Core\Form\FormStateInterface::getValue()
*/
public function &getValue($key, $default = NULL) {
$exists = NULL;
$value =& NestedArray::getValue($this->getValues(), (array) $key, $exists);
if (!$exists) {
$value = $default;
}
return $value;
}
/**
* Implements \Drupal\Core\Form\FormStateInterface::setValues()
*/
public function setValues(array $values) {
$existing_values =& $this->getValues();
$existing_values = $values;
return $this;
}
/**
* Implements \Drupal\Core\Form\FormStateInterface::setValue()
*/
public function setValue($key, $value) {
NestedArray::setValue($this->getValues(), (array) $key, $value, TRUE);
return $this;
}
/**
* Implements \Drupal\Core\Form\FormStateInterface::unsetValue()
*/
public function unsetValue($key) {
NestedArray::unsetValue($this->getValues(), (array) $key);
return $this;
}
/**
* Implements \Drupal\Core\Form\FormStateInterface::hasValue()
*/
public function hasValue($key) {
$exists = NULL;
$value = NestedArray::getValue($this->getValues(), (array) $key, $exists);
return $exists && isset($value);
}
/**
* Implements \Drupal\Core\Form\FormStateInterface::isValueEmpty()
*/
public function isValueEmpty($key) {
$exists = NULL;
$value = NestedArray::getValue($this->getValues(), (array) $key, $exists);
return !$exists || empty($value);
}
/**
* Implements \Drupal\Core\Form\FormStateInterface::setValueForElement()
*/
public function setValueForElement(array $element, $value) {
return $this->setValue($element['#parents'], $value);
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overrides |
---|---|---|---|---|
FormStateValuesTrait::getValue | public | function | Implements \Drupal\Core\Form\FormStateInterface::getValue() | |
FormStateValuesTrait::getValues | abstract public | function | Implements \Drupal\Core\Form\FormStateInterface::getValues() | 3 |
FormStateValuesTrait::hasValue | public | function | Implements \Drupal\Core\Form\FormStateInterface::hasValue() | |
FormStateValuesTrait::isValueEmpty | public | function | Implements \Drupal\Core\Form\FormStateInterface::isValueEmpty() | |
FormStateValuesTrait::setValue | public | function | Implements \Drupal\Core\Form\FormStateInterface::setValue() | |
FormStateValuesTrait::setValueForElement | public | function | Implements \Drupal\Core\Form\FormStateInterface::setValueForElement() | |
FormStateValuesTrait::setValues | public | function | Implements \Drupal\Core\Form\FormStateInterface::setValues() | |
FormStateValuesTrait::unsetValue | public | function | Implements \Drupal\Core\Form\FormStateInterface::unsetValue() |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.