You are here

public function MaestroIfTask::validateTaskEditForm in Maestro 8.2

Same name and namespace in other branches
  1. 3.x src/Plugin/EngineTasks/MaestroIfTask.php \Drupal\maestro\Plugin\EngineTasks\MaestroIfTask::validateTaskEditForm()

This method must be called by the template builder in order to validate the form entry values before saving.

Overrides MaestroEngineTaskInterface::validateTaskEditForm

File

src/Plugin/EngineTasks/MaestroIfTask.php, line 323

Class

MaestroIfTask
Maestro If Task Plugin.

Namespace

Drupal\maestro\Plugin\EngineTasks

Code

public function validateTaskEditForm(array &$form, FormStateInterface $form_state) {
  $method = $form_state
    ->getValue('method');
  switch ($method) {
    case 'byvariable':
      $byvars = $form_state
        ->getValue('byvariable');
      if (empty($byvars['variable'])) {
        $form_state
          ->setErrorByName('byvariable][variable', $this
          ->t('When doing an IF by variable, you must provide a variable to IF on.'));
      }
      if (empty($byvars['operator'])) {
        $form_state
          ->setErrorByName('byvariable][operator', $this
          ->t('When doing an IF by variable, you must provide a operator.'));
      }
      if (empty($byvars['variable_value'])) {
        $form_state
          ->setErrorByName('byvariable][variable_value', $this
          ->t('When doing an IF by variable, you must provide a variable value.'));
      }
      $form['byvariable']['#open'] = TRUE;
      $form['bystatus']['#open'] = FALSE;
      break;
    case 'bystatus':

      // This condition may not even occur, but if for some reason the form is corrupt, we need to ensure we have a value.
      $byvars = $form_state
        ->getValue('bystatus');
      if (empty($byvars['status'])) {
        $form_state
          ->setErrorByName('bystatus][status', $this
          ->t('When doing an IF by statys, you must provide a status value.'));
      }
      $form['byvariable']['#open'] = FALSE;
      $form['bystatus']['#open'] = TRUE;
      break;
  }
}