Skip to content

Commit

Permalink
Always show elements in the back end
Browse files Browse the repository at this point in the history
  • Loading branch information
aschempp committed Apr 5, 2024
1 parent 2480c30 commit d2c4b6b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ services:
arguments:
- '@Terminal42\Geoip2CountryBundle\CountryProvider'
- '@request_stack'
- '@contao.routing.scope_matcher'
tags:
- { name: contao.hook, hook: isVisibleElement }

Expand Down
7 changes: 7 additions & 0 deletions src/EventListener/VisibleElementListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

namespace Terminal42\Geoip2CountryBundle\EventListener;

use Contao\CoreBundle\Routing\ScopeMatcher;
use Contao\Model;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Terminal42\Geoip2CountryBundle\CountryProvider;

Expand All @@ -13,11 +15,16 @@ class VisibleElementListener
public function __construct(
private readonly CountryProvider $countryProvider,
private readonly RequestStack $requestStack,
private readonly ScopeMatcher $scopeMatcher,
) {
}

public function __invoke(Model $element, bool $hasAccess): bool
{
if ($this->scopeMatcher->isBackendRequest($this->requestStack->getCurrentRequest() ?? Request::create(''))) {
return $hasAccess;
}

if ('show' !== $element->geoip_visibility && 'hide' !== $element->geoip_visibility) {
return $hasAccess;
}
Expand Down

0 comments on commit d2c4b6b

Please sign in to comment.