RegistrationAddAccessCheck.php in RNG - Events and Registrations 8.2
File
src/Access/RegistrationAddAccessCheck.php
View source
<?php
namespace Drupal\rng\Access;
use Drupal\Core\Routing\Access\AccessInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Session\AccountInterface;
use Symfony\Component\Routing\Route;
use Drupal\rng\Entity\RegistrationTypeInterface;
class RegistrationAddAccessCheck implements AccessInterface {
protected $entityManager;
public function __construct(EntityManagerInterface $entity_manager) {
$this->entityManager = $entity_manager;
}
public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account, RegistrationTypeInterface $registration_type = NULL) {
if ($event = $route
->getDefault('event')) {
$context = [
'event' => $route_match
->getParameter($event),
];
$access_control_handler = $this->entityManager
->getAccessControlHandler('registration');
if ($registration_type) {
return $access_control_handler
->createAccess($registration_type
->id(), $account, $context, TRUE);
}
else {
return $access_control_handler
->createAccess(NULL, $account, $context, TRUE);
}
}
return AccessResult::forbidden();
}
}