Skip to content

Commit

Permalink
Add compatibility for Contao 5.4+ (#225)
Browse files Browse the repository at this point in the history
* Fix security.helper service

* use interface instead

* use AuthorizationCheckerInterface

* use TokenStorageInterface
  • Loading branch information
fritzmg authored Jul 5, 2024
1 parent 3f5c017 commit c4b91e7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"require": {
"php": "^8.1",
"contao/core-bundle": "^4.13 || ^5.0",
"symfony/mime": "^5.4 || ^6.0 || ^7.0"
"symfony/mime": "^5.4 || ^6.0 || ^7.0",
"symfony/security-core": "^5.4 || ^6.0 || ^7.0"
},
"require-dev": {
"contao/manager-plugin": "^2.0",
Expand Down
6 changes: 3 additions & 3 deletions src/DoctrineOrmHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Doctrine\DBAL\Connection;
use Doctrine\Persistence\ObjectManager;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;

class DoctrineOrmHelper
{
Expand All @@ -27,7 +27,7 @@ public function __construct(
private readonly Connection $connection,
private readonly DcaRelationsManager $dcaRelationsManager,
private readonly RouterInterface $router,
private readonly Security $security,
private readonly TokenStorageInterface $tokenStorage,
) {
}

Expand Down Expand Up @@ -82,7 +82,7 @@ public function createObjectVersion(ObjectManager $objectManager, object $entity
$versions = new Versions($objectManager->getClassMetadata($entity::class)->getTableName(), $entity->getId());

// Set the frontend user, if any
if (($user = $this->security->getUser()) instanceof FrontendUser) {
if (($user = $this->tokenStorage->getToken()?->getUser()) instanceof FrontendUser) {
$versions->setUsername($user->username);
$versions->setUserId(0);
}
Expand Down
4 changes: 2 additions & 2 deletions src/EventListener/DcaAjaxOperationsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
use Symfony\Component\Asset\Packages;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;

class DcaAjaxOperationsListener
{
Expand All @@ -32,7 +32,7 @@ public function __construct(
private readonly Packages $packages,
private readonly RequestStack $requestStack,
private readonly ScopeMatcher $scopeMatcher,
private readonly Security $security,
private readonly AuthorizationCheckerInterface $security,
private readonly ContaoCsrfTokenManager $tokenManager,
) {
}
Expand Down

0 comments on commit c4b91e7

Please sign in to comment.