Skip to content

Commit

Permalink
fix: make sure messagePayload and getLaunchPresentation exist
Browse files Browse the repository at this point in the history
  • Loading branch information
bartlomiejmarszal committed Jun 13, 2024
1 parent 52e8ce8 commit 62b08d1
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion models/classes/LtiService.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use core_kernel_classes_Property;
use core_kernel_classes_Resource;
use oat\generis\model\GenerisRdf;
use OAT\Library\Lti1p3Core\Message\Payload\Claim\LaunchPresentationClaim;
use OAT\Library\Lti1p3Core\Message\Payload\LtiMessagePayloadInterface;
use OAT\Library\Lti1p3Core\Message\Payload\MessagePayloadInterface;
use OAT\Library\Lti1p3Core\Registration\RegistrationRepositoryInterface;
Expand Down Expand Up @@ -124,7 +125,7 @@ public function createLti1p3Session(
$userId->getIdentifier(),
$userId->getName(),
$userId->getEmail(),
$userId->getLocale() ?? $messagePayload->getLaunchPresentation()->getLocale()
$userId->getLocale() ?? $this->getLocaleFromMessagePayload($messagePayload)
),
new TenantDataSessionContext(end($clientIdParts))
];
Expand Down Expand Up @@ -232,4 +233,13 @@ public static function singleton()
{
return ServiceManager::getServiceManager()->get(static::class);
}

private function getLocaleFromMessagePayload(LtiMessagePayloadInterface $messagePayload): ?string
{
if ($messagePayload && $messagePayload->getLaunchPresentation() instanceof LaunchPresentationClaim) {
return $messagePayload->getLaunchPresentation()->getLocale();
}

return null;
}
}

0 comments on commit 62b08d1

Please sign in to comment.