Returns the field states for a given element.

Paramètres

array[] $field_states: An array of field state configuration.

\Drupal\Core\Form\FormStateInterface $form_state: Provides an interface for an object containing the current state of a form.

array $context: An associative array containing the following key-value pairs:

  • form: The form structure to which widgets are being attached. This may be a full form structure, or a sub-element of a larger form.
  • widget: The widget plugin instance.
  • items: The field values, as a \Drupal\Core\Field\FieldItemListInterface object.
  • delta: The order of this item in the array of subelements (0, 1, 2, etc).
  • default: A boolean indicating whether the form is being shown as a dummy form to set default values.

array $element: The field widget form element as constructed by \Drupal\Core\Field\WidgetBaseInterface::form().

array $parents: The current element's parents in the form.

Return value

array An array of states to render.

1 call to FieldStateManager::getStates()
FieldStateManager::apply dans src/FieldStateManager.php
Apply the field states to a form element.

Fichier

src/FieldStateManager.php, line 295

Classe

FieldStateManager
Manages field state plugins.

Namespace

Drupal\field_states_ui

Code

protected function getStates(array $field_states, FormStateInterface $form_state, array $context, array $element, array $parents) {
    $states = [];
    foreach ($field_states as $state) {
        if (!isset($state['id'])) {
            continue;
        }
        try {
            
            /** @var \Drupal\field_states_ui\FieldStateInterface $field_state */
            $field_state = $this->createInstance($state['id'], $state);
        } catch (\Exception $exception) {
            continue;
        }
        $field_state->applyState($states, $form_state, $context, $element, $parents);
    }
    return $states;
}