Mercurial > hg > isophonics-drupal-site
view core/lib/Drupal/Core/EventSubscriber/MenuRouterRebuildSubscriber.php @ 16:c2387f117808
Routine composer update
author | Chris Cannam |
---|---|
date | Tue, 10 Jul 2018 15:07:59 +0100 |
parents | 4c8ae668cc8c |
children | af1871eacc83 |
line wrap: on
line source
<?php namespace Drupal\Core\EventSubscriber; use Drupal\Core\Cache\Cache; use Drupal\Core\Lock\LockBackendInterface; use Drupal\Core\Menu\MenuLinkManagerInterface; use Drupal\Core\Routing\RoutingEvents; use Symfony\Component\EventDispatcher\Event; use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** * Rebuilds the default menu links and runs menu-specific code if necessary. */ class MenuRouterRebuildSubscriber implements EventSubscriberInterface { /** * @var \Drupal\Core\Lock\LockBackendInterface */ protected $lock; /** * The menu link plugin manager. * * @var \Drupal\Core\Menu\MenuLinkManagerInterface */ protected $menuLinkManager; /** * Constructs the MenuRouterRebuildSubscriber object. * * @param \Drupal\Core\Lock\LockBackendInterface $lock * The lock backend. * @param \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager * The menu link plugin manager. */ public function __construct(LockBackendInterface $lock, MenuLinkManagerInterface $menu_link_manager) { $this->lock = $lock; $this->menuLinkManager = $menu_link_manager; } /** * Rebuilds the menu links and deletes the local_task cache tag. * * @param \Symfony\Component\EventDispatcher\Event $event * The event object. */ public function onRouterRebuild(Event $event) { $this->menuLinksRebuild(); Cache::invalidateTags(['local_task']); } /** * Perform menu-specific rebuilding. */ protected function menuLinksRebuild() { if ($this->lock->acquire(__FUNCTION__)) { $transaction = db_transaction(); try { // Ensure the menu links are up to date. $this->menuLinkManager->rebuild(); // Ignore any database replicas temporarily. db_ignore_replica(); } catch (\Exception $e) { $transaction->rollBack(); watchdog_exception('menu', $e); } $this->lock->release(__FUNCTION__); } else { // Wait for another request that is already doing this work. // We choose to block here since otherwise the router item may not // be available during routing resulting in a 404. $this->lock->wait(__FUNCTION__); } } /** * {@inheritdoc} */ public static function getSubscribedEvents() { // Run after CachedRouteRebuildSubscriber. $events[RoutingEvents::FINISHED][] = ['onRouterRebuild', 100]; return $events; } }