Skip to content

Commit

Permalink
Merge pull request #3145 from bolt/fix/backend_url_in_menu
Browse files Browse the repository at this point in the history
Ensure correct links in menu, when changing `backend_url` in `services.yaml`
  • Loading branch information
Joossensei authored Mar 29, 2022
2 parents 77dcec6 + e512fcc commit 55cde73
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ services:
$projectDir: '%kernel.project_dir%'
$publicFolder: '%bolt.public_folder%'
$tablePrefix: '%bolt.table_prefix%'
$backendUrl: '%bolt.backend_url%'
$rememberLifetime: '%bolt.remember_lifetime%'

_instanceof:
Expand Down
9 changes: 7 additions & 2 deletions src/Menu/BackendMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,25 @@ final class BackendMenu implements BackendMenuBuilderInterface
/** @var Security */
private $security;

/** @var string */
private $backendUrl = '/bolt';

public function __construct(
BackendMenuBuilder $menuBuilder,
TagAwareCacheInterface $cache,
RequestStack $requestStack,
Stopwatch $stopwatch,
Config $config,
Security $security
Security $security,
string $backendUrl = 'bolt'
) {
$this->cache = $cache;
$this->menuBuilder = $menuBuilder;
$this->requestStack = $requestStack;
$this->stopwatch = $stopwatch;
$this->config = $config;
$this->security = $security;
$this->backendUrl = preg_replace('/[^\pL\d,]+/u', '', $backendUrl);
}

public function buildAdminMenu(): array
Expand All @@ -64,7 +69,7 @@ public function buildAdminMenu(): array
$username = '';
}

$cacheKey = 'bolt.backendMenu_' . $locale . '_' . $username;
$cacheKey = 'bolt.backendMenu_' . $locale . '_' . $this->backendUrl . '_' . $username;

$menu = $this->cache->get($cacheKey, function (ItemInterface $item) {
$item->expiresAfter($this->config->get('general/caching/backend_menu'));
Expand Down

0 comments on commit 55cde73

Please sign in to comment.