class UserEnrollInviteController in Open Social 10.2.x
Same name and namespace in other branches
- 8.9 modules/social_features/social_event/modules/social_event_invite/src/Controller/UserEnrollInviteController.php \Drupal\social_event_invite\Controller\UserEnrollInviteController
- 10.3.x modules/social_features/social_event/modules/social_event_invite/src/Controller/UserEnrollInviteController.php \Drupal\social_event_invite\Controller\UserEnrollInviteController
- 10.0.x modules/social_features/social_event/modules/social_event_invite/src/Controller/UserEnrollInviteController.php \Drupal\social_event_invite\Controller\UserEnrollInviteController
- 10.1.x modules/social_features/social_event/modules/social_event_invite/src/Controller/UserEnrollInviteController.php \Drupal\social_event_invite\Controller\UserEnrollInviteController
Accepts or declines an event enrollment invite.
@package Drupal\social_event_invite\Controller
Hierarchy
- class \Drupal\Core\Controller\ControllerBase implements ContainerInjectionInterface uses LoggerChannelTrait, MessengerTrait, RedirectDestinationTrait, StringTranslationTrait
- class \Drupal\social_event_invite\Controller\CancelEnrollInviteController
- class \Drupal\social_event_invite\Controller\UserEnrollInviteController
- class \Drupal\social_event_invite\Controller\CancelEnrollInviteController
Expanded class hierarchy of UserEnrollInviteController
File
- modules/
social_features/ social_event/ modules/ social_event_invite/ src/ Controller/ UserEnrollInviteController.php, line 18
Namespace
Drupal\social_event_invite\ControllerView source
class UserEnrollInviteController extends CancelEnrollInviteController {
/**
* {@inheritdoc}
*/
public function updateEnrollmentInvite(EventEnrollmentInterface $event_enrollment, $accept_decline) {
// Just some sanity checks.
if (!empty($event_enrollment)) {
// When the user accepted the invite,
// we set the field_request_or_invite_status to approved.
if ($accept_decline === '1') {
$event_enrollment->field_request_or_invite_status->value = EventEnrollmentInterface::INVITE_ACCEPTED_AND_JOINED;
$event_enrollment->field_enrollment_status->value = '1';
$statusMessage = $this
->getMessage($event_enrollment, $accept_decline);
if (!empty($statusMessage)) {
// Lets delete all messages to keep the messages clean.
$this
->messenger()
->deleteAll();
$this
->messenger()
->addStatus($statusMessage);
}
}
elseif ($accept_decline === '0') {
$event_enrollment->field_request_or_invite_status->value = EventEnrollmentInterface::REQUEST_OR_INVITE_DECLINED;
$statusMessage = $this
->getMessage($event_enrollment, $accept_decline);
if (!empty($statusMessage)) {
// Lets delete all messages to keep the messages clean.
$this
->messenger()
->deleteAll();
$this
->messenger()
->addStatus($statusMessage);
}
}
// And finally save (update) this updated $event_enrollment.
// @todo maybe think of deleting approved/declined records from the db?
$event_enrollment
->save();
// Invalidate cache.
$tags = [];
$tags[] = 'enrollment:' . $event_enrollment->field_event->value . '-' . $this->currentUser
->id();
$tags[] = 'event_content_list:entity:' . $this->currentUser
->id();
Cache::invalidateTags($tags);
}
// Get the redirect destination we're given in the request for the response.
$destination = Url::fromRoute('view.user_event_invites.page_user_event_invites', [
'user' => $this->currentUser
->id(),
])
->toString();
return new RedirectResponse($destination);
}
/**
* Generates a nice message for the user.
*
* @param \Drupal\social_event\EventEnrollmentInterface $event_enrollment
* The event enrollment.
* @param string $accept_decline
* The approve (1) or decline (0) number.
*
* @return \Drupal\Core\StringTranslation\TranslatableMarkup|null
* The message.
*/
public function getMessage(EventEnrollmentInterface $event_enrollment, $accept_decline) {
$statusMessage = NULL;
// Get the target event id.
$target_event_id = $event_enrollment
->get('field_event')
->getValue();
// Get the event node.
$event = $this
->entityTypeManager()
->getStorage('node')
->load($target_event_id[0]['target_id']);
// Only if we have an event, we perform the rest of the logic.
if (!empty($event)) {
// Build the link to the event node.
$link = Link::createFromRoute($this
->t('@node', [
'@node' => $event
->get('title')->value,
]), 'entity.node.canonical', [
'node' => $event
->id(),
])
->toString();
// Nice message with link to the event the user has enrolled in.
if (!empty($event
->get('title')->value) && $accept_decline === '1') {
$statusMessage = $this
->t('You have accepted the invitation for the @event event.', [
'@event' => $link,
]);
}
elseif (!empty($event
->get('title')->value) && $accept_decline === '0') {
$statusMessage = $this
->t('You have declined the invitation for the @event event.', [
'@event' => $link,
]);
}
}
return $statusMessage;
}
/**
* {@inheritdoc}
*/
public function access(AccountInterface $account) {
// Get the parameter from the request that has been done.
$user_parameter = $this->requestStack
->getCurrentRequest()->attributes
->get('user');
// Check if it's the same that is in the current session's account.
if ($account
->id() === $user_parameter) {
return AccessResult::allowed();
}
return AccessResult::neutral();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CancelEnrollInviteController:: |
protected | property |
The current user. Overrides ControllerBase:: |
|
CancelEnrollInviteController:: |
protected | property | The request stack. | |
CancelEnrollInviteController:: |
public | function | Updates the enrollment request. | |
CancelEnrollInviteController:: |
public static | function |
Instantiates a new instance of this class. Overrides ControllerBase:: |
|
CancelEnrollInviteController:: |
public | function | UpdateEnrollRequestController constructor. | |
ControllerBase:: |
protected | property | The configuration factory. | |
ControllerBase:: |
protected | property | The entity form builder. | |
ControllerBase:: |
protected | property | The entity type manager. | |
ControllerBase:: |
protected | property | The form builder. | 2 |
ControllerBase:: |
protected | property | The key-value storage. | 1 |
ControllerBase:: |
protected | property | The language manager. | 1 |
ControllerBase:: |
protected | property | The module handler. | 2 |
ControllerBase:: |
protected | property | The state service. | |
ControllerBase:: |
protected | function | Returns the requested cache bin. | |
ControllerBase:: |
protected | function | Retrieves a configuration object. | |
ControllerBase:: |
private | function | Returns the service container. | |
ControllerBase:: |
protected | function | Returns the current user. | 1 |
ControllerBase:: |
protected | function | Retrieves the entity form builder. | |
ControllerBase:: |
protected | function | Retrieves the entity type manager. | |
ControllerBase:: |
protected | function | Returns the form builder service. | 2 |
ControllerBase:: |
protected | function | Returns a key/value storage collection. | 1 |
ControllerBase:: |
protected | function | Returns the language manager service. | 1 |
ControllerBase:: |
protected | function | Returns the module handler. | 2 |
ControllerBase:: |
protected | function | Returns a redirect response object for the specified route. | |
ControllerBase:: |
protected | function | Returns the state storage service. | |
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. | |
UserEnrollInviteController:: |
public | function |
Checks access for a specific request. Overrides CancelEnrollInviteController:: |
|
UserEnrollInviteController:: |
public | function | Generates a nice message for the user. | |
UserEnrollInviteController:: |
public | function |