You are here

public function EventAccessForm::validateForm in RNG - Events and Registrations 8

Same name and namespace in other branches
  1. 8.2 src/Form/EventAccessForm.php \Drupal\rng\Form\EventAccessForm::validateForm()
  2. 3.x src/Form/EventAccessForm.php \Drupal\rng\Form\EventAccessForm::validateForm()

Form validation handler.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides FormBase::validateForm

File

src/Form/EventAccessForm.php, line 314

Class

EventAccessForm
Form to edit event access.

Namespace

Drupal\rng\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  $event = $this->event;
  $event_meta = $this->eventManager
    ->getMeta($event);
  $trigger = 'rng_event.register';
  if ($event_meta
    ->isDefaultRules($trigger)) {
    $form_state
      ->setError($form, $this
      ->t('This event is using default rules.'));
    return;
  }

  // Component_id => [operation => enabled?, ...]
  $component_operations = [];
  foreach ($form_state
    ->getValue('table') as $row) {
    foreach ($row as $cell) {
      $enabled = !empty($cell['enabled']);
      $operation = $cell['operation'];
      $component_id = $cell['component_id'];
      $component_operations[$component_id][$operation] = $enabled;
    }
  }
  $form_state
    ->setValue('component_operations', $component_operations);
}