SocialCoreController.php in Open Social 8.9
File
modules/social_features/social_core/src/Controller/SocialCoreController.php
View source
<?php
namespace Drupal\social_core\Controller;
use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\TempStore\PrivateTempStoreFactory;
use Drupal\views_bulk_operations\Form\ViewsBulkOperationsFormTrait;
use Drupal\views_bulk_operations\Service\ViewsBulkOperationsActionProcessorInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class SocialCoreController extends ControllerBase {
use ViewsBulkOperationsFormTrait;
protected $tempStoreFactory;
protected $actionProcessor;
public function __construct(PrivateTempStoreFactory $tempStoreFactory, ViewsBulkOperationsActionProcessorInterface $actionProcessor) {
$this->tempStoreFactory = $tempStoreFactory;
$this->actionProcessor = $actionProcessor;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('tempstore.private'), $container
->get('views_bulk_operations.processor'));
}
public function accessDenied() {
$frontpage = $this
->config('system.site')
->get('page.front');
$text = $this
->t("<p>You have insufficient permissions to view the page you're trying to access. There could be several reasons for this:</p><ul><li>You are trying to edit content you're not allowed to edit.</li><li>You are trying to view content (from a group) you don't have access to.</li><li>You are trying to access administration pages.</li></ul><p>Click the back button of your browser to go back where you came from or click <a href=\":url\">here</a> to go to the homepage</p>", [
':url' => $frontpage,
]);
return [
'#markup' => $text,
];
}
public function stream() {
$element = [
'#markup' => '',
];
return $element;
}
public function updateSelection($view_id, $display_id, Request $request) {
$view_data = $this
->getTempstoreData($view_id, $display_id);
if (empty($view_data)) {
throw new NotFoundHttpException();
}
if ($view_id === 'group_manage_members') {
$group_id = $request->attributes
->get('group');
if (!empty($group_id) && !empty($view_data['group_id'])) {
if ($group_id !== $view_data['group_id']) {
$view_data['list'] = [];
$view_data['group_id'] = $group_id;
$view_data['total_results'] = 0;
}
}
}
if ($view_id === 'event_manage_enrollments') {
$event_id = $request->attributes
->get('group');
if (!empty($event_id) && !empty($view_data['event_id'])) {
if ($event_id !== $view_data['event_id']) {
$view_data['list'] = [];
$view_data['event_id'] = $event_id;
$view_data['total_results'] = 0;
}
}
}
$list = $request->request
->get('list');
$op = $request->request
->get('op', 'check');
if (!empty($view_data['exclude_mode'])) {
if ($op === 'add') {
$op = 'remove';
}
elseif ($op === 'remove') {
$op = 'add';
}
}
switch ($op) {
case 'add':
foreach ($list as $bulkFormKey) {
if (!isset($view_data['list'][$bulkFormKey])) {
$view_data['list'][$bulkFormKey] = $this
->getListItem($bulkFormKey);
}
}
break;
case 'remove':
foreach ($list as $bulkFormKey) {
if (isset($view_data['list'][$bulkFormKey])) {
unset($view_data['list'][$bulkFormKey]);
}
}
break;
case 'method_include':
unset($view_data['exclude_mode']);
$view_data['list'] = [];
break;
case 'method_exclude':
$view_data['exclude_mode'] = TRUE;
$view_data['list'] = [];
break;
}
$this
->setTempstoreData($view_data);
$count = empty($view_data['exclude_mode']) ? count($view_data['list']) : $view_data['total_results'] - count($view_data['list']);
$response = new AjaxResponse();
$response
->setData([
'count' => $count,
]);
return $response;
}
public function myInvitesUserPage() {
$core_invites = \Drupal::service('social_core.invite');
if (!empty($core_invites
->getInviteData('name'))) {
return $this
->redirect($core_invites
->getInviteData('name'), [
'user' => $this
->currentUser()
->id(),
]);
}
return $this
->redirect('social_user.user_home', [
'user' => $this
->currentUser()
->id(),
]);
}
}