public function DataComparison::validateForm in Business Rules 8
Same name and namespace in other branches
- 2.x src/Plugin/BusinessRulesCondition/DataComparison.php \Drupal\business_rules\Plugin\BusinessRulesCondition\DataComparison::validateForm()
Performs the form validation.
Parameters
array $form: The form array.
\Drupal\Core\Form\FormStateInterface $form_state: The form state object.
Overrides BusinessRulesItemPluginBase::validateForm
File
- src/Plugin/ BusinessRulesCondition/ DataComparison.php, line 94 
Class
- DataComparison
- Class DataComparison.
Namespace
Drupal\business_rules\Plugin\BusinessRulesConditionCode
public function validateForm(array &$form, FormStateInterface $form_state) {
  $item = $form_state
    ->getFormObject()
    ->getEntity();
  if (!$item
    ->isNew()) {
    $textarea_fields = [
      'contains',
      '==',
      'starts_with',
      'ends_with',
      '!=',
    ];
    $value_to_compare = $form_state
      ->getValue('value_to_compare');
    $operator = $form_state
      ->getValue('operator');
    if (!in_array($operator, $textarea_fields) && stristr($value_to_compare, chr(10))) {
      $form_state
        ->setErrorByName('value_to_compare', t('This operator only allows one value in one line. Please remove the additional lines.'));
    }
    elseif ($operator != 'empty' && trim($value_to_compare) == '') {
      $form_state
        ->setErrorByName('value_to_compare', t('This operator require one value to be compared with.'));
    }
  }
}