public function ScheduleTask::validateForm in Business Rules 8
Same name and namespace in other branches
- 2.x src/Plugin/BusinessRulesAction/ScheduleTask.php \Drupal\business_rules\Plugin\BusinessRulesAction\ScheduleTask::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/ ScheduleTask.php, line 147
Class
- ScheduleTask
- Class ScheduleTask.
Namespace
Drupal\business_rules\Plugin\BusinessRulesActionCode
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()) {
// Validate Time offset.
if (!is_numeric($form_state
->getValue('time_offset'))) {
$form_state
->setErrorByName('time_offset', t('Time offset must be a number.'));
}
// Validate target field.
$entity_type = $form_state
->getValue('target_entity_type');
$bundle = $form_state
->getValue('target_bundle');
$field = $form_state
->getValue('field');
$fields = $this->util
->getBundleFields($entity_type, $bundle);
if (isset($fields[$field]) && !in_array($fields[$field]
->getArguments()['@type'], [
'changed',
'created',
'timestamp',
'datetime',
])) {
$form_state
->setErrorByName('field', t('Field type must be type of: "changed", "created", "timestamp" or "datetime"'));
}
}
}