class LtiToolProviderProvisionEventSubscriber in LTI Tool Provider 8
Same name and namespace in other branches
- 2.x modules/lti_tool_provider_provision/src/EventSubscriber/LtiToolProviderProvisionEventSubscriber.php \Drupal\lti_tool_provider_provision\EventSubscriber\LtiToolProviderProvisionEventSubscriber
Hierarchy
- class \Drupal\lti_tool_provider_provision\EventSubscriber\LtiToolProviderProvisionEventSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of LtiToolProviderProvisionEventSubscriber
1 string reference to 'LtiToolProviderProvisionEventSubscriber'
- lti_tool_provider_provision.services.yml in modules/
lti_tool_provider_provision/ lti_tool_provider_provision.services.yml - modules/lti_tool_provider_provision/lti_tool_provider_provision.services.yml
1 service uses LtiToolProviderProvisionEventSubscriber
File
- modules/
lti_tool_provider_provision/ src/ EventSubscriber/ LtiToolProviderProvisionEventSubscriber.php, line 16
Namespace
Drupal\lti_tool_provider_provision\EventSubscriberView source
class LtiToolProviderProvisionEventSubscriber implements EventSubscriberInterface {
/**
* @var ConfigFactoryInterface
*/
protected $configFactory;
/**
* @var ProvisionService
*/
private $provisionService;
/**
* @var EventDispatcherInterface
*/
protected $eventDispatcher;
/**
* LtiToolProviderProvisionEventSubscriber constructor.
* @param ConfigFactoryInterface $configFactory
* @param ProvisionService $provisionService
* @param EventDispatcherInterface $eventDispatcher
*/
public function __construct(ConfigFactoryInterface $configFactory, ProvisionService $provisionService, EventDispatcherInterface $eventDispatcher) {
$this->configFactory = $configFactory;
$this->provisionService = $provisionService;
$this->eventDispatcher = $eventDispatcher;
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() : array {
return [
LtiToolProviderLaunchRedirectEvent::EVENT_NAME => 'onLaunch',
LtiToolProviderProvisionCreateProvisionEvent::EVENT_NAME => 'onCreateProvision',
];
}
/**
* @param LtiToolProviderLaunchRedirectEvent $event
*/
public function onLaunch(LtiToolProviderLaunchRedirectEvent $event) {
$context = $event
->getContext();
try {
if ($entity = $this->provisionService
->provision($context)) {
if ($this->configFactory
->get('lti_tool_provider_provision.settings')
->get('entity_sync')) {
$this->provisionService
->syncProvisionedEntity($context, $entity);
$entity
->save();
}
$provisionEvent = new LtiToolProviderProvisionEvent($context, $entity, $entity
->toUrl()
->toString());
LtiToolProviderEvent::dispatchEvent($this->eventDispatcher, $provisionEvent);
if ($provisionEvent
->isCancelled()) {
throw new Exception($event
->getMessage());
}
if ($this->configFactory
->get('lti_tool_provider_provision.settings')
->get('entity_redirect')) {
$event
->setDestination($provisionEvent
->getDestination());
}
}
} catch (Exception $e) {
$event
->sendLtiError($context, $e
->getMessage());
Drupal::logger('lti_tool_provider_provision')
->error($e
->getMessage());
}
}
/**
* @param LtiToolProviderProvisionCreateProvisionEvent $event
*/
public function onCreateProvision(LtiToolProviderProvisionCreateProvisionEvent $event) {
$context = $event
->getContext();
$access = true;
if ($this->configFactory
->get('lti_tool_provider_provision.settings')
->get('allowed_roles_enabled')) {
$access = false;
$ltiRoles = parse_roles($context['roles']);
$allowedRoles = $this->configFactory
->get('lti_tool_provider_provision.settings')
->get('allowed_roles');
foreach ($ltiRoles as $ltiRole) {
if (isset($allowedRoles[$ltiRole]) && $allowedRoles[$ltiRole]) {
$access = true;
break;
}
}
}
if (!$access) {
$event
->cancel('Unable to provision entity.');
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
LtiToolProviderProvisionEventSubscriber:: |
protected | property | ||
LtiToolProviderProvisionEventSubscriber:: |
protected | property | ||
LtiToolProviderProvisionEventSubscriber:: |
private | property | ||
LtiToolProviderProvisionEventSubscriber:: |
public static | function | ||
LtiToolProviderProvisionEventSubscriber:: |
public | function | ||
LtiToolProviderProvisionEventSubscriber:: |
public | function | ||
LtiToolProviderProvisionEventSubscriber:: |
public | function | LtiToolProviderProvisionEventSubscriber constructor. |