update node and menu update event suscribers
This commit is contained in:
parent
4432406876
commit
ac7b816de6
|
@ -10,6 +10,7 @@ use App\Core\Factory\Site\NodeFactory;
|
|||
use App\Core\Manager\EntityManager;
|
||||
use App\Core\Repository\Site\NodeRepository;
|
||||
use App\Core\Slugify\CodeSlugify;
|
||||
use App\Core\Cache\SymfonyCacheManager;
|
||||
|
||||
/**
|
||||
* class MenuEventSubscriber.
|
||||
|
@ -22,17 +23,20 @@ class MenuEventSubscriber extends EntityManagerEventSubscriber
|
|||
protected NodeRepository $nodeRepository;
|
||||
protected EntityManager $entityManager;
|
||||
protected CodeSlugify $slugify;
|
||||
protected SymfonyCacheManager $cacheManager;
|
||||
|
||||
public function __construct(
|
||||
NodeFactory $nodeFactory,
|
||||
NodeRepository $nodeRepository,
|
||||
EntityManager $entityManager,
|
||||
CodeSlugify $slugify
|
||||
CodeSlugify $slugify,
|
||||
SymfonyCacheManager $cacheManager
|
||||
) {
|
||||
$this->nodeFactory = $nodeFactory;
|
||||
$this->nodeRepository = $nodeRepository;
|
||||
$this->entityManager = $entityManager;
|
||||
$this->slugify = $slugify;
|
||||
$this->cacheManager = $cacheManager;
|
||||
}
|
||||
|
||||
public function support(EntityInterface $entity)
|
||||
|
@ -58,11 +62,16 @@ class MenuEventSubscriber extends EntityManagerEventSubscriber
|
|||
|
||||
$menu = $event->getEntity();
|
||||
|
||||
if (0 !== count($menu->getNodes())) {
|
||||
if (count($menu->getNodes()) > 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
$rootNode = $menu->getRootNode();
|
||||
|
||||
if (!$rootNode) {
|
||||
$rootNode = $this->nodeFactory->create($menu);
|
||||
}
|
||||
|
||||
$childNode = $this->nodeFactory->create($menu, '/');
|
||||
$childNode
|
||||
->setParent($rootNode)
|
||||
|
@ -78,6 +87,8 @@ class MenuEventSubscriber extends EntityManagerEventSubscriber
|
|||
$this->entityManager->flush();
|
||||
|
||||
$this->nodeRepository->persistAsFirstChild($childNode, $rootNode);
|
||||
|
||||
$this->cacheManager->cleanAll();
|
||||
}
|
||||
|
||||
public function onUpdate(EntityManagerEvent $event)
|
||||
|
|
|
@ -10,6 +10,7 @@ use App\Core\Event\EntityManager\EntityManagerEvent;
|
|||
use App\Core\EventSuscriber\EntityManagerEventSubscriber;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
use App\Core\Cache\SymfonyCacheManager;
|
||||
|
||||
/**
|
||||
* class SiteEventSubscriber.
|
||||
|
@ -19,10 +20,12 @@ use Symfony\Component\HttpKernel\KernelInterface;
|
|||
class SiteEventSubscriber extends EntityManagerEventSubscriber
|
||||
{
|
||||
protected KernelInterface $kernel;
|
||||
protected SymfonyCacheManager $cacheManager;
|
||||
|
||||
public function __construct(KernelInterface $kernel)
|
||||
public function __construct(KernelInterface $kernel, SymfonyCacheManager $cacheManager)
|
||||
{
|
||||
$this->kernel = $kernel;
|
||||
$this->cacheManager = $cacheManager;
|
||||
}
|
||||
|
||||
public function support(EntityInterface $entity)
|
||||
|
@ -36,7 +39,11 @@ class SiteEventSubscriber extends EntityManagerEventSubscriber
|
|||
return;
|
||||
}
|
||||
|
||||
$this->cleanCache();
|
||||
if ($event->getEntity() instanceof Node) {
|
||||
$this->cacheManager->cleanRouting();
|
||||
} else {
|
||||
$this->cacheManager->cleanAll();
|
||||
}
|
||||
}
|
||||
|
||||
public function onCreate(EntityManagerEvent $event)
|
||||
|
@ -48,17 +55,4 @@ class SiteEventSubscriber extends EntityManagerEventSubscriber
|
|||
{
|
||||
return $this->onUpdate($event);
|
||||
}
|
||||
|
||||
protected function cleanCache()
|
||||
{
|
||||
$finder = new Finder();
|
||||
$finder
|
||||
->in($this->kernel->getCacheDir())
|
||||
->name('url_*.php*')
|
||||
;
|
||||
|
||||
foreach ($finder as $file) {
|
||||
unlink((string) $file->getPathname());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -120,3 +120,4 @@
|
|||
"Enter your account username or email address. An e-mail will be sent to you to initiate the password change procedure. ": "Saisissez le nom d'utilisateur ou l'adresse e-mail de votre compte. Un e-mail vous sera envoyé pour enclancher la procédure de changement de mot de passe."
|
||||
"Show the login page": "Afficher la page de connexion"
|
||||
"A password reset request has been made. If you are the source of this request, click on the link below or copy and paste the address if the link does not work.": "Une demande de réinitialisation de mot de passe a été réalisée. Si vous êtes à l'origine de cette demande, cliquer sur le lien ci-dessous ou copier et coller l'adresse si le lien ne fonctionne pas."
|
||||
"Edit the routing": "Éditez le routage"
|
||||
|
|
|
@ -113,7 +113,7 @@
|
|||
|
||||
<span class="ml-3 btn-group">
|
||||
{% if node.hasExternalUrl %}
|
||||
<a href="{{ node.url }}" class="btn btn-sm border border-secondary btn-light">
|
||||
<a href="{{ safe_node_url(node) }}" class="btn btn-sm border border-secondary btn-light">
|
||||
<span class="fa fa-sign-out-alt text-muted"></span>
|
||||
</a>
|
||||
{% else %}
|
||||
|
@ -122,11 +122,21 @@
|
|||
{{ node.url }}
|
||||
</span>
|
||||
{% else %}
|
||||
<a href="{{ url(node.routeName) }}" target="_blank" class="btn btn-sm border border-secondary btn-light">
|
||||
{% set url = safe_node_url(node) %}
|
||||
|
||||
{% if url %}
|
||||
<a href="{{ url ? url : '#' }}" target="_blank" class="btn btn-sm border border-secondary btn-light">
|
||||
{{ node.url }}
|
||||
</a>
|
||||
{% endif %}
|
||||
|
||||
{% if url is same as(null) %}
|
||||
<span class="btn btn-sm border border-secondary btn-light" title="{{ 'Edit the routing'|trans }}">
|
||||
<span class="fa fa-exclamation"></span>
|
||||
</span>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
{% if node.controller %}
|
||||
<span title="{{ node.controller }}" data-toggle="tooltip" data-placement="top" class="btn btn-sm border border-secondary btn-light">
|
||||
<span class="fa fa-dice-d6"></span>
|
||||
|
|
|
@ -39,6 +39,10 @@ class SiteRouteLoader extends Loader
|
|||
continue;
|
||||
}
|
||||
|
||||
if (null === $node->getUrl()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($node->hasExternalUrl()) {
|
||||
continue;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue