public function VariableDataComparison::validateForm in Business Rules 8
Same name and namespace in other branches
- 2.x src/Plugin/BusinessRulesCondition/VariableDataComparison.php \Drupal\business_rules\Plugin\BusinessRulesCondition\VariableDataComparison::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/ VariableDataComparison.php, line 78
Class
- VariableDataComparison
- Class VariableDataComparison.
Namespace
Drupal\business_rules\Plugin\BusinessRulesConditionCode
public function validateForm(array &$form, FormStateInterface $form_state) {
/** @var \Drupal\Core\Entity\EntityInterface $item */
$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.'));
}
}
}