You are here

public function EventTypeRuleComponentEdit::buildForm in RNG - Events and Registrations 8

Same name and namespace in other branches
  1. 8.2 src/Form/EventTypeRuleComponentEdit.php \Drupal\rng\Form\EventTypeRuleComponentEdit::buildForm()
  2. 3.x 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 105

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']);
  }
  else {
    if ($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;
}