You are here

public function EventTypeRuleComponentEdit::buildForm in RNG - Events and Registrations 3.x

Same name and namespace in other branches
  1. 8.2 src/Form/EventTypeRuleComponentEdit.php \Drupal\rng\Form\EventTypeRuleComponentEdit::buildForm()
  2. 8 src/Form/EventTypeRuleComponentEdit.php \Drupal\rng\Form\EventTypeRuleComponentEdit::buildForm()

Form constructor.

Parameters

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

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

Return value

array The form structure.

Overrides FormInterface::buildForm

File

src/Form/EventTypeRuleComponentEdit.php, line 104

Class

EventTypeRuleComponentEdit
Configure event settings.

Namespace

Drupal\rng\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, EventTypeRuleInterface $rng_event_type_rule = NULL, $component_type = NULL, $component_id = NULL) {
  $this->eventTypeRule = $rng_event_type_rule;
  $this->componentType = $component_type;
  $this->componentId = $component_id;
  if ($this->componentType == 'condition') {
    $manager = 'conditionManager';
    $components = $this->eventTypeRule
      ->getConditions();
    $configuration = $components[$this->componentId];
    $plugin_id = $configuration['id'];
    unset($configuration['id']);
  }
  elseif ($this->componentType == 'action') {
    $manager = 'actionManager';
    $components = $this->eventTypeRule
      ->getActions();
    $plugin_id = $components[$this->componentId]['id'];
    $configuration = $components[$this->componentId]['configuration'];
  }
  else {
    return $form;
  }
  $this->plugin = $this->{$manager}
    ->createInstance($plugin_id, $configuration);
  $form += $this->plugin
    ->buildConfigurationForm($form, $form_state);
  $form['actions'] = [
    '#type' => 'actions',
  ];
  $form['actions']['submit'] = [
    '#type' => 'submit',
    '#value' => t('Save'),
    '#button_type' => 'primary',
  ];
  return $form;
}