You are here

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

Same name and namespace in other branches
  1. 8.2 src/Form/MessageActionForm.php \Drupal\rng\Form\MessageActionForm::buildForm()
  2. 8 src/Form/MessageActionForm.php \Drupal\rng\Form\MessageActionForm::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/MessageActionForm.php, line 77

Class

MessageActionForm
Creates a rule with a rng_courier_message action.

Namespace

Drupal\rng\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, EntityInterface $rng_event = NULL) {
  $event = clone $rng_event;
  $this->actionPlugin
    ->setConfiguration([
    'active' => FALSE,
  ]);
  $form_state
    ->set('event', $event);
  $triggers = [
    'rng:custom:date' => $this
      ->t('To all registrations, on a date.'),
    (string) $this
      ->t('Registrations') => [
      'entity:registration:new' => $this
        ->t('To a single registration, when it is created.'),
      'entity:registration:update' => $this
        ->t('To a single registration, when it is updated.'),
    ],
  ];
  $form['trigger'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Trigger'),
    '#description' => $this
      ->t('When should this message be sent?'),
    '#options' => $triggers,
    '#default_value' => 'now',
  ];
  $form['actions'] = [
    '#type' => 'actions',
  ];
  $form['actions']['submit'] = [
    '#type' => 'submit',
    '#value' => t('Create message'),
  ];
  $form['actions']['cancel'] = [
    '#type' => 'link',
    '#title' => $this
      ->t('Cancel'),
    '#url' => Url::fromRoute('rng.event.' . $event
      ->getEntityTypeId() . '.messages', [
      $event
        ->getEntityTypeId() => $event
        ->id(),
    ]),
  ];
  return $form;
}