You are here

public static function ChangeFieldInfo::validateAddFieldForm in Business Rules 8

Same name and namespace in other branches
  1. 2.x src/Plugin/BusinessRulesAction/ChangeFieldInfo.php \Drupal\business_rules\Plugin\BusinessRulesAction\ChangeFieldInfo::validateAddFieldForm()

Validate the add field operation.

Parameters

array $form: The form array.

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

1 call to ChangeFieldInfo::validateAddFieldForm()
ChangeFieldInfo::validateForm in src/Plugin/BusinessRulesAction/ChangeFieldInfo.php
Plugin form validator.

File

src/Plugin/BusinessRulesAction/ChangeFieldInfo.php, line 260

Class

ChangeFieldInfo
Class ChangeFieldInfo.

Namespace

Drupal\business_rules\Plugin\BusinessRulesAction

Code

public static function validateAddFieldForm(array &$form, FormStateInterface $form_state) {
  $field = $form_state
    ->getValue('fields');
  $field_field = $field['new.field']['field'];
  $field_action = $field['new.field']['action'];
  if (empty($field_action) && !empty($field_field) || !empty($field_action) && empty($field_field)) {
    $form_state
      ->setErrorByName('fields', t("Please, fill all field data or none of them."));
  }

  // The title field can't be optional.
  if ($field['new.field']['field'] == 'title' && $field['new.field']['action'] == self::MAKE_OPTIONAL) {
    $form_state
      ->setErrorByName('fields', t('The title field cannot be optional.'));
  }
}