You are here

protected static function ElementBase::prepareState in Select (or other) 8

Same name and namespace in other branches
  1. 4.x src/Element/ElementBase.php \Drupal\select_or_other\Element\ElementBase::prepareState()

Prepares an array to be used as a state in a form API #states array.

Parameters

string $state: The state the element should have.

string $element_name: The name of the element on which this state depends.

string $value_key: The key used to select the property on which the state depends.

mixed $value: The value a property should have to trigger the state.

Return value

array An array with state information to be used in a #states array.

2 calls to ElementBase::prepareState()
Buttons::addStatesHandling in src/Element/Buttons.php
Adds a #states array to the other field to make hide/show work.
Select::addStatesHandling in src/Element/Select.php
Adds a #states array to the other field to make hide/show work.

File

src/Element/ElementBase.php, line 48

Class

ElementBase
Base class for select or other form elements.

Namespace

Drupal\select_or_other\Element

Code

protected static function prepareState($state, $element_name, $value_key, $value) {
  return [
    $state => [
      ':input[name="' . $element_name . '"]' => [
        $value_key => $value,
      ],
    ],
  ];
}