diff --git a/src/lib/EventHandlers/SystemListeners.php b/src/lib/EventHandlers/SystemListeners.php index 1c7ad262f7..c7527a6c82 100644 --- a/src/lib/EventHandlers/SystemListeners.php +++ b/src/lib/EventHandlers/SystemListeners.php @@ -12,6 +12,8 @@ * information regarding copyright and licensing. */ +use Zikula\Core\Event\GenericEvent; + /** * Event handler to override templates. */ @@ -35,6 +37,7 @@ protected function setupHandlerDefinitions() $this->addHandlerDefinition('core.preinit', 'initDB'); $this->addHandlerDefinition('core.init', 'setupCsfrProtection'); $this->addHandlerDefinition('theme.init', 'clickJackProtection'); + $this->addHandlerDefinition('zikula.link_collector', 'processHookListeners'); } /** @@ -291,4 +294,20 @@ public function clickJackProtection(Zikula_Event $event) //header("X-Content-Security-Policy: frame-ancestors 'self'"); header('X-XSS-Protection: 1'); } + + /** + * Respond to zikula.link_collector events. + * + * Create a BC Layer for the zikula.link_collector event to gather Hook-related links. + * + * @param GenericEvent $event + */ + public function processHookListeners(GenericEvent $event) + { + $event->setArgument('modname', $event->getSubject()); + $event->setArgument('modfunc', array(1 => 'getLinks')); + $event->setArgument('api', true); + $this->addHooksLink($event); + $this->addServiceLink($event); + } } diff --git a/src/lib/Zikula/Bundle/CoreBundle/CoreBundle.php b/src/lib/Zikula/Bundle/CoreBundle/CoreBundle.php index 0c29a77f6d..3bedfae3d4 100644 --- a/src/lib/Zikula/Bundle/CoreBundle/CoreBundle.php +++ b/src/lib/Zikula/Bundle/CoreBundle/CoreBundle.php @@ -8,6 +8,7 @@ use Symfony\Component\HttpKernel\Bundle\Bundle; use Zikula\Bundle\CoreBundle\DependencyInjection\Compiler\DoctrinePass; use Zikula\Bundle\CoreBundle\DependencyInjection\Compiler\RegisterCoreListenersPass; +use Zikula\Bundle\CoreBundle\DependencyInjection\Compiler\LinkContainerPass; class CoreBundle extends Bundle { @@ -18,6 +19,8 @@ public function build(ContainerBuilder $container) $container->addCompilerPass(new RegisterCoreListenersPass(), PassConfig::TYPE_AFTER_REMOVING); + $container->addCompilerPass(new LinkContainerPass()); + // todo - see if we can do this only on module install/upgrade - drak $container->addCompilerPass(new ValidateServiceDefinitionsPass(), PassConfig::TYPE_AFTER_REMOVING); } diff --git a/src/lib/Zikula/Bundle/CoreBundle/DependencyInjection/Compiler/LinkContainerPass.php b/src/lib/Zikula/Bundle/CoreBundle/DependencyInjection/Compiler/LinkContainerPass.php new file mode 100644 index 0000000000..de7e860964 --- /dev/null +++ b/src/lib/Zikula/Bundle/CoreBundle/DependencyInjection/Compiler/LinkContainerPass.php @@ -0,0 +1,23 @@ +hasDefinition('zikula.link_container_collector')) { + return; + } + + $definition = $container->getDefinition('zikula.link_container_collector'); + + foreach ($container->findTaggedServiceIds('zikula.link_container') as $id => $linkContainer) { + $definition->addMethodCall('addContainer', array(new Reference($id))); + } + } +} diff --git a/src/lib/Zikula/Bundle/CoreBundle/Resources/config/services.xml b/src/lib/Zikula/Bundle/CoreBundle/Resources/config/services.xml index da8d58a660..67741d8f03 100644 --- a/src/lib/Zikula/Bundle/CoreBundle/Resources/config/services.xml +++ b/src/lib/Zikula/Bundle/CoreBundle/Resources/config/services.xml @@ -9,6 +9,7 @@ Zikula\Bundle\CoreBundle\Controller\ControllerResolver Zikula\Bundle\CoreBundle\CacheClearer + Zikula\Core\LinkContainer\LinkContainerCollector @@ -25,5 +26,8 @@ %jms_i18n_routing.locales% + + + diff --git a/src/lib/Zikula/Core/LinkContainer/LinkContainerCollector.php b/src/lib/Zikula/Core/LinkContainer/LinkContainerCollector.php new file mode 100644 index 0000000000..469db60d84 --- /dev/null +++ b/src/lib/Zikula/Core/LinkContainer/LinkContainerCollector.php @@ -0,0 +1,54 @@ +eventDispatcher = $dispatcher; + $this->linkContainers = array(); + } + + public function addContainer(LinkContainerInterface $linkContainer) + { + $this->linkContainers[$linkContainer->getBundleName()] = $linkContainer; + } + + public function getLinks($containerName, $type = LinkContainerInterface::TYPE_ADMIN) + { + $links = array(); + if ($this->hasContainer($containerName)) { + $links = $this->linkContainers[$containerName]->getLinks($type); + } + // fire event here to add more links like hooks, moduleServices, etc + $event = new GenericEvent($containerName, array('type' => $type), $links); + $links = $this->eventDispatcher->dispatch(LinkContainerInterface::EVENT_NAME, $event)->getData(); + + return $links; + } + + public function hasContainer($containerName) + { + return isset($this->linkContainers[$containerName]); + } +} \ No newline at end of file diff --git a/src/lib/Zikula/Core/LinkContainer/LinkContainerInterface.php b/src/lib/Zikula/Core/LinkContainer/LinkContainerInterface.php new file mode 100644 index 0000000000..61f01ff1e9 --- /dev/null +++ b/src/lib/Zikula/Core/LinkContainer/LinkContainerInterface.php @@ -0,0 +1,34 @@ +generate($module['capabilities']['admin']['route']); $moduleSelected = empty($moduleSelected) && strpos($view->getRequest()->getUri(), $module['url']) ? " class='Selected'" : ""; $htmlContent .= "\"\" " . $module['displayname'] . ""; - try { + + $links = $view->getContainer()->get('zikula.link_container_collector')->getLinks($module['name'], 'admin'); + if (empty($links)) { $links = (array)ModUtil::apiFunc($module['name'], 'admin', 'getLinks'); - } catch (\Exception $e) { - $links = array(); } + if ((count($links) > 0) && ($links[0] != false)) { // create second-level list from module adminLinks $htmlContent .= '