You are here

public function ReactionRuleEditForm::form in Rules 8.3

Gets the actual form array to be built.

Overrides RulesComponentFormBase::form

See also

\Drupal\Core\Entity\EntityForm::processForm()

\Drupal\Core\Entity\EntityForm::afterBuild()

File

src/Form/ReactionRuleEditForm.php, line 75

Class

ReactionRuleEditForm
Provides a form to edit a reaction rule.

Namespace

Drupal\rules\Form

Code

public function form(array $form, FormStateInterface $form_state) {
  $form['events'] = [
    '#type' => 'container',
    '#attributes' => [
      'class' => [
        'edit-events',
      ],
    ],
  ];
  $form['events']['table'] = [
    '#theme' => 'table',
    '#header' => [
      $this
        ->t('Events'),
      $this
        ->t('Operations'),
    ],
    '#empty' => $this
      ->t('None'),
  ];
  foreach ($this->entity
    ->getEventNames() as $key => $event_name) {
    $event_definition = $this->eventManager
      ->getDefinition($event_name);
    $form['events']['table']['#rows'][$key]['element'] = [
      'data' => [
        '#type' => 'item',
        '#plain_text' => $event_definition['label'],
        '#suffix' => '<div class="description">' . $this
          ->t('Machine name: @name', [
          '@name' => $event_name,
        ]) . '</div>',
      ],
    ];
    $form['events']['table']['#rows'][$key]['element']['colspan'] = 2;
  }

  // Put action buttons in the table footer.
  $links['add-event'] = [];
  $form['events']['table']['#footer'][] = [
    [
      'data' => [
        '#prefix' => '<ul class="action-links">',
        'local-action-links' => $links,
        '#suffix' => '</ul>',
      ],
      'colspan' => 2,
    ],
  ];

  // CSS to make form easier to use. Load this at end so we can override
  // styles added by #theme table.
  $form['#attached']['library'][] = 'rules/rules_ui.styles';
  $form = $this->rulesUiHandler
    ->getForm()
    ->buildForm($form, $form_state);
  return parent::form($form, $form_state);
}