backports murph-skeleton

This commit is contained in:
Simon Vieille 2021-03-25 12:00:53 +01:00
parent 249622485a
commit e69a44151d
5 changed files with 43 additions and 25 deletions

View File

@ -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 = $this->nodeFactory->create($menu);
$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)

View File

@ -8,10 +8,9 @@ use App\Core\Entity\Site\Navigation;
use App\Core\Entity\Site\Node;
use App\Core\Event\EntityManager\EntityManagerEvent;
use App\Core\EventSuscriber\EntityManagerEventSubscriber;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\Finder\Finder;
use Symfony\Component\HttpKernel\KernelInterface;
use App\Core\Cache\SymfonyCacheManager;
/**
* class SiteEventSubscriber.
@ -21,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)
@ -38,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)
@ -50,17 +55,4 @@ class SiteEventSubscriber extends EntityManagerEventSubscriber
{
return $this->onUpdate($event);
}
protected function cleanCache()
{
$application = new Application($this->kernel);
$application->setAutoExit(false);
$input = new ArrayInput([
'command' => 'cache:clear',
]);
$output = new BufferedOutput();
$application->run($input, $output);
}
}

View File

@ -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"

View File

@ -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,9 +122,19 @@
{{ node.url }}
</span>
{% else %}
<a href="{{ url(node.routeName) }}" target="_blank" class="btn btn-sm border border-secondary btn-light">
{{ node.url }}
</a>
{% 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 %}

View File

@ -39,6 +39,10 @@ class SiteRouteLoader extends Loader
continue;
}
if (null === $node->getUrl()) {
continue;
}
if ($node->hasExternalUrl()) {
continue;
}