You are here

public function EnrollRequestDeclineForm::buildForm in Open Social 8.9

Same name and namespace in other branches
  1. 10.3.x modules/social_features/social_event/src/Form/EnrollRequestDeclineForm.php \Drupal\social_event\Form\EnrollRequestDeclineForm::buildForm()
  2. 10.0.x modules/social_features/social_event/src/Form/EnrollRequestDeclineForm.php \Drupal\social_event\Form\EnrollRequestDeclineForm::buildForm()
  3. 10.1.x modules/social_features/social_event/src/Form/EnrollRequestDeclineForm.php \Drupal\social_event\Form\EnrollRequestDeclineForm::buildForm()
  4. 10.2.x modules/social_features/social_event/src/Form/EnrollRequestDeclineForm.php \Drupal\social_event\Form\EnrollRequestDeclineForm::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

modules/social_features/social_event/src/Form/EnrollRequestDeclineForm.php, line 101

Class

EnrollRequestDeclineForm
Class EnrollRequestDeclineForm.

Namespace

Drupal\social_event\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {

  // Get the event_enrollment from the request.
  $this->eventEnrollment = $this
    ->getRequest()
    ->get('event_enrollment');

  // Load the user profile to format a nice name.
  if (!empty($this->eventEnrollment)) {

    /** @var \Drupal\profile\Entity\Profile $user_profile */
    $user_profile = Profile::load($this->eventEnrollment
      ->getAccount());
    $this->fullName = $user_profile->field_profile_first_name->value . ' ' . $user_profile->field_profile_last_name->value;
  }
  $form['#attributes']['class'][] = 'form--default';
  $form['question'] = [
    '#type' => 'html_tag',
    '#tag' => 'p',
    '#value' => $this
      ->t('Are you sure you want to decline the enrollment request for @name?', [
      '@name' => $this->fullName,
    ]),
    '#weight' => 1,
    '#prefix' => '<div class="card"><div class="card__block">',
    '#suffix' => '</div></div>',
  ];
  $form['actions']['#type'] = 'actions';
  $form['actions']['cancel'] = [
    '#type' => 'link',
    '#title' => $this
      ->t('Cancel'),
    '#attributes' => [
      'class' => [
        'button',
        'button--flat',
        'btn',
        'btn-flat',
        'waves-effect',
        'waves-btn',
      ],
    ],
    '#url' => $this
      ->getCancelUrl(),
  ];
  $form['actions']['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Yes'),
    '#button_type' => 'primary',
  ];
  return $form;
}