You are here

public function ChangeFormDisplay::validateForm in Business Rules 2.x

Same name and namespace in other branches
  1. 8 src/Plugin/BusinessRulesAction/ChangeFormDisplay.php \Drupal\business_rules\Plugin\BusinessRulesAction\ChangeFormDisplay::validateForm()

Plugin form validator.

If the plugin needs to perform a form validation, override this function.

Parameters

array $form: The form array.

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

Overrides BusinessRulesItemPluginBase::validateForm

File

src/Plugin/BusinessRulesAction/ChangeFormDisplay.php, line 91

Class

ChangeFormDisplay
Class ChangeFormDisplay.

Namespace

Drupal\business_rules\Plugin\BusinessRulesAction

Code

public function validateForm(array &$form, FormStateInterface $form_state) {

  /** @var \Drupal\business_rules\ItemInterface $item */
  $item = $form_state
    ->get('business_rules_item');

  // We only can validate the form if the item is not new.
  if (!empty($item) && !$item
    ->isNew()) {
    if ($form_state
      ->getValue('selection_mode') == 'fixed') {
      if (!$form_state
        ->getValue('fixed')) {
        $form_state
          ->setErrorByName('fixed', t('Select the form mode'));
      }
    }
    elseif (!$form_state
      ->getValue('variable')) {
      $form_state
        ->setErrorByName('variable', t('Fill the variable/token'));
    }
  }
}