class LtiToolProviderAttributesEventSubscriber in LTI Tool Provider 2.x
Same name and namespace in other branches
- 8 modules/lti_tool_provider_attributes/src/EventSubscriber/LtiToolProviderAttributesEventSubscriber.php \Drupal\lti_tool_provider_attributes\EventSubscriber\LtiToolProviderAttributesEventSubscriber
Hierarchy
- class \Drupal\lti_tool_provider_attributes\EventSubscriber\LtiToolProviderAttributesEventSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of LtiToolProviderAttributesEventSubscriber
1 string reference to 'LtiToolProviderAttributesEventSubscriber'
- lti_tool_provider_attributes.services.yml in modules/
lti_tool_provider_attributes/ lti_tool_provider_attributes.services.yml - modules/lti_tool_provider_attributes/lti_tool_provider_attributes.services.yml
1 service uses LtiToolProviderAttributesEventSubscriber
File
- modules/
lti_tool_provider_attributes/ src/ EventSubscriber/ LtiToolProviderAttributesEventSubscriber.php, line 14
Namespace
Drupal\lti_tool_provider_attributes\EventSubscriberView source
class LtiToolProviderAttributesEventSubscriber implements EventSubscriberInterface {
/**
* @var ConfigFactoryInterface
*/
protected $configFactory;
/**
* @var EventDispatcherInterface
*/
protected $eventDispatcher;
/**
* LtiToolProviderAttributesEventSubscriber constructor.
*
* @param ConfigFactoryInterface $configFactory
* @param EventDispatcherInterface $eventDispatcher
*/
public function __construct(ConfigFactoryInterface $configFactory, EventDispatcherInterface $eventDispatcher) {
$this->configFactory = $configFactory;
$this->eventDispatcher = $eventDispatcher;
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() : array {
return [
LtiToolProviderAuthenticatedEvent::EVENT_NAME => 'onAuthenticated',
];
}
/**
* @param LtiToolProviderAuthenticatedEvent $event
*/
public function onAuthenticated(LtiToolProviderAuthenticatedEvent $event) {
$mapped_attributes = $this->configFactory
->get('lti_tool_provider_attributes.settings')
->get('mapped_attributes');
$context = $event
->getContext();
$user = $event
->getUser();
if ($user
->getDisplayName() === 'ltiuser') {
return;
}
if (!$mapped_attributes || !count($mapped_attributes)) {
return;
}
foreach ($mapped_attributes as $user_attribute => $lti_attribute) {
if (isset($context[$mapped_attributes[$user_attribute]]) && !empty($context[$mapped_attributes[$user_attribute]])) {
$user
->set($user_attribute, $context[$mapped_attributes[$user_attribute]]);
}
}
try {
$attributesEvent = new LtiToolProviderAttributesEvent($context, $user);
LtiToolProviderEvent::dispatchEvent($this->eventDispatcher, $attributesEvent);
if ($attributesEvent
->isCancelled()) {
throw new Exception($event
->getMessage());
}
$user
->save();
} catch (Exception $e) {
Drupal::logger('lti_tool_provider_attributes')
->error($e
->getMessage());
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
LtiToolProviderAttributesEventSubscriber:: |
protected | property | ||
LtiToolProviderAttributesEventSubscriber:: |
protected | property | ||
LtiToolProviderAttributesEventSubscriber:: |
public static | function | ||
LtiToolProviderAttributesEventSubscriber:: |
public | function | ||
LtiToolProviderAttributesEventSubscriber:: |
public | function | LtiToolProviderAttributesEventSubscriber constructor. |