Validation function for adding/editing field states.

Parameters

array $form: The whole EntityFormDisplay form array

\Drupal\Core\Form\FormStateInterface $form_state: The form state.

File

src/FieldStateManager.php, line 587

Class

FieldStateManager
Manages field state plugins.

Namespace

Drupal\field_states_ui

Code

public static function settingsValidate(array $form, FormStateInterface $form_state) {
    $trigger = $form_state->getTriggeringElement();
    $field_name = $trigger['#field_name'];
    $op = $trigger['#op'];
    if ($op == 'add') {
        $element = "fields][{$field_name}][settings_edit_form][third_party_settings][field_states_ui][form][type";
        $type = $form_state->getValue([
            'fields',
            $field_name,
            'settings_edit_form',
            'third_party_settings',
            'field_states_ui',
            'form',
            'type',
        ]);
        if (!$type) {
            $form_state->setErrorByName($element, t('You must select a field state to add.'));
        }
    }
}