Skip to content

Commit b8ec628

Browse files
authored
Merge pull request #111 from neufeind/cache-identifier-for-menu-event
[FEATURE] Add CacheIdentifierForMenuEvent in AbstractMenuCompiler
2 parents 900efeb + d585851 commit b8ec628

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

Classes/Compiler/AbstractMenuCompiler.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
use B13\Menus\CacheHelper;
1515
use B13\Menus\Domain\Repository\MenuRepository;
16+
use B13\Menus\Event\CacheIdentifierForMenuEvent;
17+
use Psr\EventDispatcher\EventDispatcherInterface;
1618
use TYPO3\CMS\Core\Context\Context;
1719
use TYPO3\CMS\Core\Context\LanguageAspect;
1820
use TYPO3\CMS\Core\Context\UserAspect;
@@ -30,12 +32,14 @@ abstract class AbstractMenuCompiler implements SingletonInterface
3032
protected MenuRepository $menuRepository;
3133
protected CacheHelper $cache;
3234
protected Context $context;
35+
protected EventDispatcherInterface $eventDispatcher;
3336

34-
public function __construct(Context $context, CacheHelper $cache, MenuRepository $menuRepository)
37+
public function __construct(Context $context, CacheHelper $cache, MenuRepository $menuRepository, EventDispatcherInterface $eventDispatcher)
3538
{
3639
$this->context = $context;
3740
$this->menuRepository = $menuRepository;
3841
$this->cache = $cache;
42+
$this->eventDispatcher = $eventDispatcher;
3943
}
4044

4145
/**
@@ -67,6 +71,9 @@ protected function generateCacheIdentifierForMenu(string $prefix, array $configu
6771
$visibility = $visibilityAspect->includeHiddenPages() ? '-with-hidden' : '';
6872
$root = $this->getCurrentSite()->getRootPageId();
6973
$identifier = $prefix . '-root-' . $root . '-language-' . $language . '-groups-' . md5(implode('_', $groupIds)) . '-' . $visibility . '-' . substr(md5(json_encode($configuration)), 0, 10);
74+
$event = new CacheIdentifierForMenuEvent($identifier);
75+
$this->eventDispatcher->dispatch($event);
76+
$identifier = $event->getIdentifier();
7077
return $identifier;
7178
}
7279

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace B13\Menus\Event;
6+
7+
class CacheIdentifierForMenuEvent
8+
{
9+
protected $identifier;
10+
11+
public function __construct(string $identifier)
12+
{
13+
$this->identifier = $identifier;
14+
}
15+
16+
public function getIdentifier(): string
17+
{
18+
return $this->identifier;
19+
}
20+
21+
public function setIdentifier(string $identifier): void
22+
{
23+
$this->identifier = $identifier;
24+
}
25+
}

0 commit comments

Comments
 (0)