Returns the field states for a given element.

Parameters

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

\Drupal\field_states_ui\FieldStateManager $manager: Manages field state plugins.

\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 field_states_ui_get_states()
field_states_ui_field_widget_alter in ./field_states_ui.form.inc
Implements hook_field_widget_form_alter().

File

./field_states_ui.form.inc, line 184

Code

function field_states_ui_get_states(array $field_states, FieldStateManager $manager, 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 = $manager->createInstance($state['id'], $state);
        } catch (\Exception $exception) {
            continue;
        }
        $field_state->applyState($states, $form_state, $context, $element, $parents);
    }
    return $states;
}