You are here

class EventAnEnrollActionForm in Open Social 8.9

Same name and namespace in other branches
  1. 8.3 modules/social_features/social_event/modules/social_event_an_enroll/src/Form/EventAnEnrollActionForm.php \Drupal\social_event_an_enroll\Form\EventAnEnrollActionForm
  2. 8.4 modules/social_features/social_event/modules/social_event_an_enroll/src/Form/EventAnEnrollActionForm.php \Drupal\social_event_an_enroll\Form\EventAnEnrollActionForm
  3. 8.5 modules/social_features/social_event/modules/social_event_an_enroll/src/Form/EventAnEnrollActionForm.php \Drupal\social_event_an_enroll\Form\EventAnEnrollActionForm
  4. 8.6 modules/social_features/social_event/modules/social_event_an_enroll/src/Form/EventAnEnrollActionForm.php \Drupal\social_event_an_enroll\Form\EventAnEnrollActionForm
  5. 8.7 modules/social_features/social_event/modules/social_event_an_enroll/src/Form/EventAnEnrollActionForm.php \Drupal\social_event_an_enroll\Form\EventAnEnrollActionForm
  6. 8.8 modules/social_features/social_event/modules/social_event_an_enroll/src/Form/EventAnEnrollActionForm.php \Drupal\social_event_an_enroll\Form\EventAnEnrollActionForm
  7. 10.3.x modules/social_features/social_event/modules/social_event_an_enroll/src/Form/EventAnEnrollActionForm.php \Drupal\social_event_an_enroll\Form\EventAnEnrollActionForm
  8. 10.0.x modules/social_features/social_event/modules/social_event_an_enroll/src/Form/EventAnEnrollActionForm.php \Drupal\social_event_an_enroll\Form\EventAnEnrollActionForm
  9. 10.1.x modules/social_features/social_event/modules/social_event_an_enroll/src/Form/EventAnEnrollActionForm.php \Drupal\social_event_an_enroll\Form\EventAnEnrollActionForm
  10. 10.2.x modules/social_features/social_event/modules/social_event_an_enroll/src/Form/EventAnEnrollActionForm.php \Drupal\social_event_an_enroll\Form\EventAnEnrollActionForm

Class EventAnEnrollActionForm.

@package Drupal\social_event_an_enroll\Form

Hierarchy

Expanded class hierarchy of EventAnEnrollActionForm

File

modules/social_features/social_event/modules/social_event_an_enroll/src/Form/EventAnEnrollActionForm.php, line 16

Namespace

Drupal\social_event_an_enroll\Form
View source
class EventAnEnrollActionForm extends EnrollActionForm {

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'event_an_enroll_action_form';
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state, Node $node = NULL) {
    $nid = $node
      ->id();
    $token = $this
      ->getRequest()->query
      ->get('token');
    if (!empty($token) && \Drupal::service('social_event_an_enroll.service')
      ->tokenExists($token, $nid)) {
      $form['event'] = [
        '#type' => 'hidden',
        '#value' => $nid,
      ];
      $form['enroll_for_this_event'] = [
        '#type' => 'submit',
        '#value' => $this
          ->t('Enrolled'),
        '#attributes' => [
          'class' => [
            'btn',
            'btn-accent',
            'btn-lg',
            'btn-raised',
            'brand-bg-accent',
            'dropdown-toggle',
            'waves-effect',
          ],
          'autocomplete' => 'off',
          'data-toggle' => 'dropdown',
          'aria-haspopup' => 'true',
          'aria-expanded' => 'false',
          'data-caret' => 'true',
        ],
      ];
      $cancel_text = $this
        ->t('Cancel enrollment');
      $form['feedback_user_has_enrolled'] = [
        '#markup' => '<ul class="dropdown-menu dropdown-menu-right"><li><a href="#" class="enroll-form-submit"> ' . $cancel_text . ' </a></li></ul>',
      ];
      $form['#attached']['library'][] = 'social_event/form_submit';
    }
    else {
      if ($this
        ->eventHasBeenFinished($node)) {
        $form['event_enrollment'] = [
          '#type' => 'submit',
          '#value' => $this
            ->t('Event has passed'),
          '#disabled' => TRUE,
          '#attributes' => [
            'class' => [
              'btn',
              'btn-accent',
              'btn-lg',
              'btn-raised',
              'brand-bg-accent',
              'waves-effect',
            ],
          ],
        ];
      }
      else {
        $attributes = [
          'class' => [
            'use-ajax',
            'js-form-submit',
            'form-submit',
            'btn',
            'btn-accent',
            'btn-lg',
          ],
          'data-dialog-type' => 'modal',
          'data-dialog-options' => json_encode([
            'title' => t('Enroll in') . ' ' . strip_tags($node
              ->getTitle()),
            'width' => 'auto',
          ]),
        ];
        $form['event_enrollment'] = [
          '#type' => 'link',
          '#title' => $this
            ->t('Enroll'),
          '#url' => Url::fromRoute('social_event_an_enroll.enroll_dialog', [
            'node' => $nid,
          ]),
          '#attributes' => $attributes,
        ];
      }
    }
    $form['#cache'] = [
      'max-age' => 0,
    ];
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $uid = $this->currentUser
      ->id();
    $token = $this
      ->getRequest()->query
      ->get('token');
    if (!empty($token)) {
      $nid = $form_state
        ->getValue('event');
      $conditions = [
        'field_account' => $uid,
        'field_event' => $nid,
        'field_token' => $token,
      ];
      $enrollments = $this->entityStorage
        ->loadByProperties($conditions);

      // Invalidate cache for our enrollment cache tag in
      // social_event_node_view_alter().
      $cache_tags[] = 'enrollment:' . $nid . '-' . $uid;
      $cache_tags[] = 'node:' . $nid;
      Cache::invalidateTags($cache_tags);
      if ($enrollment = array_pop($enrollments)) {
        $enrollment
          ->delete();
        drupal_set_message($this
          ->t('You are no longer enrolled in this event. Your personal data used for the enrollment is also deleted.'));
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
EnrollActionForm::$configFactory protected property The config factory. Overrides FormBase::$configFactory
EnrollActionForm::$currentUser protected property The current user.
EnrollActionForm::$entityStorage protected property The node storage for event enrollments.
EnrollActionForm::$entityTypeManager protected property The entity type manager.
EnrollActionForm::$moduleHandler protected property The module handler.
EnrollActionForm::$routeMatch protected property The routing matcher to get the nid. Overrides FormBase::$routeMatch
EnrollActionForm::$userStorage protected property The user storage.
EnrollActionForm::create public static function Instantiates a new instance of this class. Overrides FormBase::create
EnrollActionForm::eventHasBeenFinished protected function Function to determine if an event has been finished.
EnrollActionForm::getGroups public function Get group object where event enrollment is posted in.
EnrollActionForm::__construct public function Constructs an Enroll Action Form.
EventAnEnrollActionForm::buildForm public function Form constructor. Overrides EnrollActionForm::buildForm
EventAnEnrollActionForm::getFormId public function Returns a unique string identifying the form. Overrides EnrollActionForm::getFormId
EventAnEnrollActionForm::submitForm public function Form submission handler. Overrides EnrollActionForm::submitForm
FormBase::$requestStack protected property The request stack. 1
FormBase::config protected function Retrieves a configuration object.
FormBase::configFactory protected function Gets the config factory for this form. 1
FormBase::container private function Returns the service container.
FormBase::currentUser protected function Gets the current user.
FormBase::getRequest protected function Gets the request object.
FormBase::getRouteMatch protected function Gets the route match.
FormBase::logger protected function Gets the logger for a specific channel.
FormBase::redirect protected function Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait::redirect
FormBase::resetConfigFactory public function Resets the configuration factory.
FormBase::setConfigFactory public function Sets the config factory for this form.
FormBase::setRequestStack public function Sets the request stack object to use.
FormBase::validateForm public function Form validation handler. Overrides FormInterface::validateForm 62
LinkGeneratorTrait::$linkGenerator protected property The link generator. 1
LinkGeneratorTrait::getLinkGenerator Deprecated protected function Returns the link generator.
LinkGeneratorTrait::l Deprecated protected function Renders a link to a route given a route name and its parameters.
LinkGeneratorTrait::setLinkGenerator Deprecated public function Sets the link generator service.
LoggerChannelTrait::$loggerFactory protected property The logger channel factory service.
LoggerChannelTrait::getLogger protected function Gets the logger for a specific channel.
LoggerChannelTrait::setLoggerFactory public function Injects the logger channel factory.
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
RedirectDestinationTrait::$redirectDestination protected property The redirect destination service. 1
RedirectDestinationTrait::getDestinationArray protected function Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.
RedirectDestinationTrait::getRedirectDestination protected function Returns the redirect destination service.
RedirectDestinationTrait::setRedirectDestination public function Sets the redirect destination service.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
UrlGeneratorTrait::$urlGenerator protected property The url generator.
UrlGeneratorTrait::getUrlGenerator Deprecated protected function Returns the URL generator service.
UrlGeneratorTrait::setUrlGenerator Deprecated public function Sets the URL generator service.
UrlGeneratorTrait::url Deprecated protected function Generates a URL or path for a specific route based on the given parameters.