You are here

public function MessageListForm::buildForm in RNG - Events and Registrations 8.2

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

Class

MessageListForm
Creates message list form.

Namespace

Drupal\rng\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, EntityInterface $rng_event = NULL) {
  $form['#rng_event'] = $rng_event;

  // @todo: move trigger definitions to a discovery service.
  $rng_triggers = [
    'entity:registration:new' => $this
      ->t('Registration creation'),
    'entity:registration:update' => $this
      ->t('Registration updated'),
    'rng:custom:date' => $this
      ->t('Send on a date'),
  ];

  // Actions.
  $form['actions'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Operations'),
    '#attributes' => [
      'class' => [
        'container-inline',
      ],
    ],
    '#open' => TRUE,
  ];
  $form['actions']['operation'] = [
    '#title' => $this
      ->t('With selection'),
    '#type' => 'select',
    '#options' => [
      'enable' => $this
        ->t('Enable messages'),
      'disable' => $this
        ->t('Disable messages'),
      'delete' => $this
        ->t('Delete messages'),
    ],
    '#empty_option' => $this
      ->t(' - Select - '),
    '#button_type' => 'primary',
  ];
  $form['actions']['apply'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Apply'),
    '#button_type' => 'primary',
  ];

  // List items.
  $form['list'] = [
    '#type' => 'courier_template_collection_list',
    '#checkboxes' => TRUE,
    '#items' => [],
  ];
  foreach ($this
    ->getCommunicationRules($form['#rng_event']) as $rid => $rule) {
    $trigger_id = $rule
      ->getTriggerID();
    if ($template_collection = $this
      ->getTemplateCollectionForRule($rule)) {

      // Add description for date conditions.
      $description = NULL;
      if ($component = $this
        ->getDateCondition($rule)) {
        $condition = $component
          ->createInstance();
        $description = $condition
          ->getDateFormatted();
      }
      $form['list']['#items'][$rule
        ->id()] = [
        '#title' => $this
          ->t('@label (@status)', [
          '@label' => isset($rng_triggers[$trigger_id]) ? $rng_triggers[$trigger_id] : $trigger_id,
          '@status' => $rule
            ->isActive() ? $this
            ->t('active') : $this
            ->t('disabled'),
        ]),
        '#description' => $description,
        '#template_collection' => $template_collection,
        '#operations' => $this
          ->getOperations($rule),
      ];
    }
  }
  return $form;
}