class EventInviteEnrollActionForm in Open Social 10.3.x
Same name and namespace in other branches
- 8.9 modules/social_features/social_event/modules/social_event_invite/src/Form/EventInviteEnrollActionForm.php \Drupal\social_event_invite\Form\EventInviteEnrollActionForm
- 10.0.x modules/social_features/social_event/modules/social_event_invite/src/Form/EventInviteEnrollActionForm.php \Drupal\social_event_invite\Form\EventInviteEnrollActionForm
- 10.1.x modules/social_features/social_event/modules/social_event_invite/src/Form/EventInviteEnrollActionForm.php \Drupal\social_event_invite\Form\EventInviteEnrollActionForm
- 10.2.x modules/social_features/social_event/modules/social_event_invite/src/Form/EventInviteEnrollActionForm.php \Drupal\social_event_invite\Form\EventInviteEnrollActionForm
Class EventInviteEnrollActionForm.
@package Drupal\social_event_invite\Form
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, RedirectDestinationTrait, StringTranslationTrait
- class \Drupal\social_event\Form\EnrollActionForm implements ContainerInjectionInterface
- class \Drupal\social_event_invite\Form\EventInviteEnrollActionForm
- class \Drupal\social_event\Form\EnrollActionForm implements ContainerInjectionInterface
Expanded class hierarchy of EventInviteEnrollActionForm
File
- modules/
social_features/ social_event/ modules/ social_event_invite/ src/ Form/ EventInviteEnrollActionForm.php, line 16
Namespace
Drupal\social_event_invite\FormView source
class EventInviteEnrollActionForm extends EnrollActionForm {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'event_invite_enroll_action_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, Node $node = NULL) {
$form = parent::buildForm($form, $form_state);
$nid = $this->routeMatch
->getRawParameter('node');
$current_user = $this->currentUser;
$uid = $current_user
->id();
if (!$current_user
->isAnonymous()) {
// Check if enrollment is enabled.
if (!$this->eventEnrollService
->isEnabled($node)) {
return [];
}
$conditions = [
'field_account' => $uid,
'field_event' => $nid,
];
$enrollments = $this->entityStorage
->loadByProperties($conditions);
// If the event is invite only and you have not been invited, return.
// Unless you are the node owner or organizer.
if (empty($enrollments)) {
if ((int) $node->field_enroll_method->value === EventEnrollmentInterface::ENROLL_METHOD_INVITE && social_event_manager_or_organizer() === FALSE) {
return [];
}
}
elseif ($enrollment = array_pop($enrollments)) {
$enroll_request_status = $enrollment->field_request_or_invite_status->value;
// If user got invited perform actions.
if ($enroll_request_status == '4') {
$submit_text = $this
->t('Accept');
$form['enroll_for_this_event'] = [
'#type' => 'submit',
'#value' => $submit_text,
'#name' => 'accept_invite',
];
// Extra attributes needed for when a user is logged in.
// This will make sure the button acts like a dropdown.
$form['enroll_for_this_event']['#attributes'] = [
'class' => [
'btn',
'btn-accent brand-bg-accent',
'btn-lg btn-raised',
'dropdown-toggle',
'waves-effect',
],
];
// We need a hidden element for later usage.
$form['event_id'] = [
'#type' => 'hidden',
'#value' => $this->routeMatch
->getRawParameter('node'),
];
$form['decline_invite'] = [
'#type' => 'submit',
'#value' => '',
'#name' => 'decline_invite',
];
// Extra attributes needed for when a user is logged in.
// This will make sure the button acts like a dropdown.
$form['decline_invite']['#attributes'] = [
'class' => [
'btn',
'btn-accent brand-bg-accent',
'btn-lg btn-raised',
'dropdown-toggle',
'waves-effect',
'margin-left-s',
],
'autocomplete' => 'off',
'data-toggle' => 'dropdown',
'aria-haspopup' => 'true',
'aria-expanded' => 'false',
'data-caret' => 'true',
];
$decline_text = $this
->t('Decline');
// Add markup for the button so it will be a dropdown.
$form['decline_invite_dropdown'] = [
'#markup' => '<ul class="dropdown-menu dropdown-menu-right"><li><a href="#" class="enroll-form-submit"> ' . $decline_text . ' </a></li></ul>',
];
// Add a hidden operation we can fill with jquery when declining.
$form['operation'] = [
'#type' => 'hidden',
'#default_value' => '',
];
$form['#attached']['library'][] = 'social_event/form_submit';
}
}
}
// For AN users it can be rendered on a Public event with
// invite only as option. Let's make it similar to a Group experience
// where there is no button rendered.
// We unset it here because in the parent form and this form
// a lot of times this button get's overridden.
if ($current_user
->isAnonymous()) {
unset($form['enroll_for_this_event']);
}
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state);
$operation = $form_state
->getValue('operation');
$current_user = $this->currentUser;
$uid = $current_user
->id();
$nid = $form_state
->getValue('event') ?? $this->routeMatch
->getRawParameter('node');
$conditions = [
'field_account' => $uid,
'field_event' => $nid,
];
$enrollments = $this->entityStorage
->loadByProperties($conditions);
// @todo also clear the breadcrumb cachetags.
// Invalidate cache for our enrollment cache tag in
// social_event_node_view_alter().
$tags = [];
$tags[] = 'enrollment:' . $nid . '-' . $uid;
$tags[] = 'event_content_list:entity:' . $uid;
Cache::invalidateTags($tags);
if ($enrollment = array_pop($enrollments)) {
// Only trigger when the user is invited.
if ($enrollment->field_request_or_invite_status && (int) $enrollment->field_request_or_invite_status->value === EventEnrollmentInterface::INVITE_PENDING_REPLY) {
// Delete any messages since it would show a 'successful enrollment'.
$this
->messenger()
->deleteAll();
// Accept the invite.
$enrollment->field_enrollment_status->value = '1';
$enrollment->field_request_or_invite_status->value = EventEnrollmentInterface::INVITE_ACCEPTED_AND_JOINED;
// If decline is chosen, set invite to declined.
if ($operation === 'decline') {
// Delete any messages since it would show a 'successful enrollment'.
$this
->messenger()
->deleteAll();
$enrollment->field_enrollment_status->value = '0';
$enrollment->field_request_or_invite_status->value = EventEnrollmentInterface::REQUEST_OR_INVITE_DECLINED;
}
$enrollment
->save();
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
public | function | 2 | |
DependencySerializationTrait:: |
public | function | 2 | |
EnrollActionForm:: |
protected | property |
The config factory. Overrides FormBase:: |
|
EnrollActionForm:: |
protected | property | The current user. | |
EnrollActionForm:: |
protected | property | The node storage for event enrollments. | |
EnrollActionForm:: |
protected | property | The entity type manager. | |
EnrollActionForm:: |
protected | property | The event enroll service. | |
EnrollActionForm:: |
protected | property | The module handler. | |
EnrollActionForm:: |
protected | property |
The routing matcher to get the nid. Overrides FormBase:: |
|
EnrollActionForm:: |
protected | property | The user storage. | |
EnrollActionForm:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
|
EnrollActionForm:: |
protected | function | Function to determine if an event has been finished. | |
EnrollActionForm:: |
public | function | Get group object where event enrollment is posted in. | |
EnrollActionForm:: |
public | function | Constructs an Enroll Action Form. | |
EventInviteEnrollActionForm:: |
public | function |
Form constructor. Overrides EnrollActionForm:: |
|
EventInviteEnrollActionForm:: |
public | function |
Returns a unique string identifying the form. Overrides EnrollActionForm:: |
|
EventInviteEnrollActionForm:: |
public | function |
Form submission handler. Overrides EnrollActionForm:: |
|
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | function | Retrieves a configuration object. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 3 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function | Returns a redirect response object for the specified route. | |
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
FormBase:: |
public | function |
Form validation handler. Overrides FormInterface:: |
72 |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 27 |
MessengerTrait:: |
public | function | Gets the messenger. | 27 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |