class GroupRequestController in Open Social 10.3.x
Same name and namespace in other branches
- 8.9 modules/social_features/social_group/modules/social_group_request/src/Controller/GroupRequestController.php \Drupal\social_group_request\Controller\GroupRequestController
- 10.0.x modules/social_features/social_group/modules/social_group_request/src/Controller/GroupRequestController.php \Drupal\social_group_request\Controller\GroupRequestController
- 10.1.x modules/social_features/social_group/modules/social_group_request/src/Controller/GroupRequestController.php \Drupal\social_group_request\Controller\GroupRequestController
- 10.2.x modules/social_features/social_group/modules/social_group_request/src/Controller/GroupRequestController.php \Drupal\social_group_request\Controller\GroupRequestController
Returns responses for Group request routes.
Hierarchy
- class \Drupal\Core\Controller\ControllerBase implements ContainerInjectionInterface uses LoggerChannelTrait, MessengerTrait, RedirectDestinationTrait, StringTranslationTrait
- class \Drupal\social_group_request\Controller\GroupRequestController
Expanded class hierarchy of GroupRequestController
1 file declares its use of GroupRequestController
- SocialGroupRequestRouteSubscriber.php in modules/
social_features/ social_group/ modules/ social_group_request/ src/ Routing/ SocialGroupRequestRouteSubscriber.php
File
- modules/
social_features/ social_group/ modules/ social_group_request/ src/ Controller/ GroupRequestController.php, line 27
Namespace
Drupal\social_group_request\ControllerView source
class GroupRequestController extends ControllerBase {
/**
* The cache tags invalidator.
*
* @var \Drupal\Core\Cache\CacheTagsInvalidatorInterface
*/
protected $cacheTagsInvalidator;
/**
* GroupRequestController constructor.
*
* @param \Drupal\Core\Form\FormBuilderInterface $form_builder
* The form builder.
* @param \Drupal\Core\Entity\EntityFormBuilderInterface $entity_form_builder
* The entity form builder.
* @param \Drupal\Core\Messenger\MessengerInterface $messenger
* The messenger.
* @param \Drupal\Core\Cache\CacheTagsInvalidatorInterface $cache_tags_invalidator
* The cache tags invalidator.
* @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
* The string translation.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\Core\Session\AccountInterface $current_user
* The current user.
*/
public function __construct(FormBuilderInterface $form_builder, EntityFormBuilderInterface $entity_form_builder, MessengerInterface $messenger, CacheTagsInvalidatorInterface $cache_tags_invalidator, TranslationInterface $string_translation, EntityTypeManagerInterface $entity_type_manager, AccountInterface $current_user) {
$this->formBuilder = $form_builder;
$this->entityFormBuilder = $entity_form_builder;
$this
->setMessenger($messenger);
$this->cacheTagsInvalidator = $cache_tags_invalidator;
$this
->setStringTranslation($string_translation);
$this->entityTypeManager = $entity_type_manager;
$this->currentUser = $current_user;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('form_builder'), $container
->get('entity.form_builder'), $container
->get('messenger'), $container
->get('cache_tags.invalidator'), $container
->get('string_translation'), $container
->get('entity_type.manager'), $container
->get('current_user'));
}
/**
* Return the title for approve request confirmation page.
*/
public function getTitleApproveRequest(GroupInterface $group, GroupContentInterface $group_content) {
return $this
->t('Approve membership request for the group @group_title', [
'@group_title' => $group
->label(),
]);
}
/**
* Return the title for reject request confirmation page.
*/
public function getTitleRejectRequest(GroupInterface $group, GroupContentInterface $group_content) {
return $this
->t('Reject membership request for the group @group_title', [
'@group_title' => $group
->label(),
]);
}
/**
* Builds the form to create new membership on membership request approve.
*/
public function approveRequest(GroupInterface $group, GroupContentInterface $group_content) {
/** @var \Drupal\group\Plugin\GroupContentEnablerInterface $plugin */
$plugin = $group
->getGroupType()
->getContentPlugin('group_membership');
// Pre-populate a group membership from Membership request.
$group_content = $this
->entityTypeManager()
->getStorage('group_content')
->create([
'type' => $plugin
->getContentTypeConfigId(),
'gid' => $group
->id(),
'entity_id' => $group_content
->getEntity()
->id(),
]);
$this->cacheTagsInvalidator
->invalidateTags([
'request-membership:' . $group
->id(),
]);
return $this
->entityFormBuilder()
->getForm($group_content, 'add');
}
/**
* Callback to request membership.
*/
public function requestMembership(GroupInterface $group) {
$response = new AjaxResponse();
$contentTypeConfigId = $group
->getGroupType()
->getContentPlugin('group_membership_request')
->getContentTypeConfigId();
$request = $this
->entityTypeManager()
->getStorage('group_content')
->getQuery()
->condition('type', $contentTypeConfigId)
->condition('gid', $group
->id())
->condition('entity_id', $this
->currentUser()
->id())
->condition('grequest_status', GroupMembershipRequest::REQUEST_PENDING)
->count()
->execute();
if ($request == 0) {
$request_form = $this
->formBuilder()
->getForm(GroupRequestMembershipRequestForm::class, $group);
$response
->addCommand(new OpenModalDialogCommand($this
->t('Request to join'), $request_form, [
'width' => '582px',
'dialogClass' => 'social_group-popup',
]));
}
return $response;
}
/**
* Callback to request membership for anonymous.
*/
public function anonymousRequestMembership(GroupInterface $group) {
$request_form = $this
->formBuilder()
->getForm(GroupRequestMembershipRequestAnonymousForm::class, $group);
$response = new AjaxResponse();
$response
->addCommand(new OpenModalDialogCommand($this
->t('Request to join'), $request_form, [
'width' => '337px',
'dialogClass' => 'social_group-popup social_group-popup--anonymous',
]));
return $response;
}
/**
* Callback to cancel the request of membership.
*/
public function cancelRequest(GroupInterface $group) {
$content_type_config_id = $group
->getGroupType()
->getContentPlugin('group_membership_request')
->getContentTypeConfigId();
$requests = $this
->entityTypeManager()
->getStorage('group_content')
->loadByProperties([
'type' => $content_type_config_id,
'gid' => $group
->id(),
'entity_id' => $this
->currentUser()
->id(),
'grequest_status' => GroupMembershipRequest::REQUEST_PENDING,
]);
foreach ($requests as $request) {
$request
->delete();
}
$this
->messenger()
->addMessage($this
->t('Membership has been successfully denied.'));
$this->cacheTagsInvalidator
->invalidateTags([
'request-membership:' . $group
->id(),
]);
return $this
->redirect('social_group.stream', [
'group' => $group
->id(),
]);
}
/**
* Checks access for a specific route request to see if user can see requests.
*
* @param \Drupal\Core\Session\AccountInterface $account
* Run access checks for this account.
*
* @return \Drupal\Core\Access\AccessResultInterface
* The access result.
*/
public function routeAccess(AccountInterface $account) {
// @todo refactor this when Group entity query access lands.
$has_administer_users = $account
->hasPermission('administer members');
if ($has_administer_users) {
return AccessResult::allowed();
}
$group = _social_group_get_current_group();
if (!$group instanceof Group) {
$group_id = \Drupal::routeMatch()
->getParameter('group');
// Views upcasting is lame.
if (!isset($group_id)) {
$group_id = \Drupal::routeMatch()
->getParameter('arg_0');
}
$group = Group::load($group_id);
}
$is_group_page = isset($group);
$is_group_manager = $group
->hasPermission('administer members', $account);
return AccessResult::allowedIf($is_group_page && $is_group_manager);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ControllerBase:: |
protected | property | The configuration factory. | |
ControllerBase:: |
protected | property | The current user service. | 1 |
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. | |
GroupRequestController:: |
protected | property | The cache tags invalidator. | |
GroupRequestController:: |
public | function | Callback to request membership for anonymous. | |
GroupRequestController:: |
public | function | Builds the form to create new membership on membership request approve. | |
GroupRequestController:: |
public | function | Callback to cancel the request of membership. | |
GroupRequestController:: |
public static | function |
Instantiates a new instance of this class. Overrides ControllerBase:: |
|
GroupRequestController:: |
public | function | Return the title for approve request confirmation page. | |
GroupRequestController:: |
public | function | Return the title for reject request confirmation page. | |
GroupRequestController:: |
public | function | Callback to request membership. | |
GroupRequestController:: |
public | function | Checks access for a specific route request to see if user can see requests. | |
GroupRequestController:: |
public | function | GroupRequestController constructor. | |
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. |