You are here

public static function FormTrait::addElementState in Markdown 8.2

Adds a #states selector to an element.

Parameters

array $element: An element to add the state to, passed by reference.

string $state: The state that will be triggered.

string $name: The name of the element used for conditions.

array $conditions: The conditions of $name that trigger $state.

array $parents: An array of parents.

1 call to FormTrait::addElementState()
SubformState::addElementState in src/Form/SubformState.php
Adds a #states selector to an element.

File

src/Traits/FormTrait.php, line 40

Class

FormTrait
Trait providing helpful methods when dealing with forms.

Namespace

Drupal\markdown\Traits

Code

public static function addElementState(array &$element, $state, $name, array $conditions, array $parents = NULL) {

  // If parents weren't provided, attempt to extract it from the element.
  if (!isset($parents)) {
    $parents = isset($element['#parents']) ? $element['#parents'] : [];
  }

  // Add the state.
  if ($selector = static::getElementSelector($name, $parents)) {
    if (!isset($element['#states'][$state][$selector])) {
      $element['#states'][$state][$selector] = [];
    }
    $element['#states'][$state][$selector] = NestedArray::mergeDeep($element['#states'][$state][$selector], $conditions);
  }
}