You are here

public function SocialEventManagersAddEnrolleeForm::buildForm in Open Social 8.5

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_event/modules/social_event_managers/src/Form/SocialEventManagersAddEnrolleeForm.php \Drupal\social_event_managers\Form\SocialEventManagersAddEnrolleeForm::buildForm()
  2. 8.6 modules/social_features/social_event/modules/social_event_managers/src/Form/SocialEventManagersAddEnrolleeForm.php \Drupal\social_event_managers\Form\SocialEventManagersAddEnrolleeForm::buildForm()
  3. 8.7 modules/social_features/social_event/modules/social_event_managers/src/Form/SocialEventManagersAddEnrolleeForm.php \Drupal\social_event_managers\Form\SocialEventManagersAddEnrolleeForm::buildForm()
  4. 8.8 modules/social_features/social_event/modules/social_event_managers/src/Form/SocialEventManagersAddEnrolleeForm.php \Drupal\social_event_managers\Form\SocialEventManagersAddEnrolleeForm::buildForm()
  5. 10.3.x modules/social_features/social_event/modules/social_event_managers/src/Form/SocialEventManagersAddEnrolleeForm.php \Drupal\social_event_managers\Form\SocialEventManagersAddEnrolleeForm::buildForm()
  6. 10.0.x modules/social_features/social_event/modules/social_event_managers/src/Form/SocialEventManagersAddEnrolleeForm.php \Drupal\social_event_managers\Form\SocialEventManagersAddEnrolleeForm::buildForm()
  7. 10.1.x modules/social_features/social_event/modules/social_event_managers/src/Form/SocialEventManagersAddEnrolleeForm.php \Drupal\social_event_managers\Form\SocialEventManagersAddEnrolleeForm::buildForm()
  8. 10.2.x modules/social_features/social_event/modules/social_event_managers/src/Form/SocialEventManagersAddEnrolleeForm.php \Drupal\social_event_managers\Form\SocialEventManagersAddEnrolleeForm::buildForm()

Defines the settings form for Post entities.

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 Form definition array.

Overrides FormInterface::buildForm

File

modules/social_features/social_event/modules/social_event_managers/src/Form/SocialEventManagersAddEnrolleeForm.php, line 124

Class

SocialEventManagersAddEnrolleeForm
Class SocialEventTypeSettings.

Namespace

Drupal\social_event_managers\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form['#attributes']['class'][] = 'card card__block form--default form-wrapper form-group';
  if (empty($nid)) {
    $node = \Drupal::routeMatch()
      ->getParameter('node');
    if ($node instanceof NodeInterface) {

      // You can get nid and anything else you need from the node object.
      $nid = $node
        ->id();
    }
    elseif (!is_object($node)) {
      $nid = $node;
    }
  }

  // Load the current Event enrollments so we can check duplicates.
  $storage = \Drupal::entityTypeManager()
    ->getStorage('event_enrollment');
  $enrollments = $storage
    ->loadByProperties([
    'field_event' => $nid,
  ]);
  $enrollmentIds = [];
  foreach ($enrollments as $enrollment) {
    $enrollmentIds[] = $enrollment
      ->getAccount();
  }
  $form['name'] = [
    '#type' => 'social_enrollment_entity_autocomplete',
    '#selection_handler' => 'social',
    '#selection_settings' => [
      'skip_entity' => $enrollmentIds,
    ],
    '#target_type' => 'user',
    '#tags' => TRUE,
    '#description' => $this
      ->t('To add multiple members, separate each member with a comma ( , ).'),
    '#title' => $this
      ->t('Select members to add'),
  ];
  $form['actions']['cancel'] = [
    '#type' => 'link',
    '#title' => t('Cancel'),
    '#url' => Url::fromRoute('view.event_manage_enrollments.page_manage_enrollments', [
      'node' => $nid,
    ]),
  ];
  $form['actions']['submit'] = [
    '#prefix' => '<div class="form-actions">',
    '#suffix' => '</div>',
    '#type' => 'submit',
    '#value' => $this
      ->t('Save'),
    '#button_type' => 'primary',
  ];
  $form['#cache']['contexts'][] = 'user';
  return $form;
}