class FormHelper (View source)

Provides helpers to operate on forms.

Methods

static 
rewriteStatesSelector(array $elements, string $search, string $replace)

Rewrites #states selectors in a render element.

static 
processStatesArray(array $conditions, string $search, string $replace)

Helps recursively rewrite #states selectors.

static 
processStates(array $elements)

Adds JavaScript to change the state of an element based on another element.

Details

static rewriteStatesSelector(array $elements, string $search, string $replace)

Rewrites #states selectors in a render element.

When a structure of elements is being altered, their HTML selectors may change. In such cases calling this method will check if there are any states in element and its children, and rewrite selectors in those states.

Parameters

array $elements

A render array element having a #states property.

string $search

A partial or entire jQuery selector string to replace in #states.

string $replace

The string to replace all instances of $search with.

See also

\Drupal\Core\Form\self::processStates()

static protected processStatesArray(array $conditions, string $search, string $replace)

Helps recursively rewrite #states selectors.

Not to be confused with self::processStates(), which just prepares states for rendering.

Parameters

array $conditions

States conditions array.

string $search

A partial or entire jQuery selector string to replace in #states.

string $replace

The string to replace all instances of $search with.

See also

\Drupal\Core\Form\self::rewriteStatesSelector()

static processStates(array $elements)

Adds JavaScript to change the state of an element based on another element.

A "state" means a certain property of a DOM element, such as "visible" or "checked", which depends on a state or value of another element on the page. In general, states are HTML attributes and DOM element properties, which are applied initially, when page is loaded, depending on elements' default values, and then may change due to user interaction.

Since states are driven by JavaScript only, it is important to understand that all states are applied on presentation only, none of the states force any server-side logic, and that they will not be applied for site visitors without JavaScript support. All modules implementing states have to make sure that the intended logic also works without JavaScript being enabled.

states is an associative array in the form of:

Parameters

array $elements

A render array element having a #states property as described above.

See also

JavascriptStatesForm
JavascriptStatesTest