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 .= '';
diff --git a/src/lib/legacy/viewplugins/function.modulelinks.php b/src/lib/legacy/viewplugins/function.modulelinks.php
index 7d3953abc9..cc9f4d9599 100644
--- a/src/lib/legacy/viewplugins/function.modulelinks.php
+++ b/src/lib/legacy/viewplugins/function.modulelinks.php
@@ -30,6 +30,7 @@
* last Class for the last element (optional)
* seperator Link seperator (optional)
* class CSS class (optional).
+ * returnAsArray return results as array, not as formatted html - MUST set assign
*
* @param array $params All attributes passed to this function from the template.
* @param Zikula_View $view Reference to the Zikula_View object.
@@ -44,6 +45,7 @@ function smarty_function_modulelinks($params, Zikula_View $view)
$menuItemClass = isset($params['itemclass']) ? $params['itemclass'] : '';
$menuItemFirst = isset($params['first']) ? $params['first'] : '';
$menuItemLast = isset($params['last']) ? $params['last'] : '';
+ $returnAsArray = isset($params['returnAsArray']) ? (boolean) $params['returnAsArray'] : false;
if (empty($menuLinks)) {
if (!isset($params['modname']) || !ModUtil::available($params['modname'])) {
@@ -59,17 +61,20 @@ function smarty_function_modulelinks($params, Zikula_View $view)
$params['type'] = isset($params['type']) ? $params['type'] : 'admin';
- // get the links from the module API
- $menuLinks = ModUtil::apiFunc($params['modname'], $params['type'], 'getLinks', $params);
+ // get the menu links
+ // try the Core-2.0 way first, then try the legacy way.
+ $menuLinks = $view->getContainer()->get('zikula.link_container_collector')->getLinks($params['modname'], $params['type']);
+ if (empty($menuLinks)) {
+ $menuLinks = ModUtil::apiFunc($params['modname'], $params['type'], 'getLinks', $params);
+ }
}
- // return if there are no links to print
- if (!$menuLinks) {
+ // return if there are no links to print or template has requested to returnAsArray
+ if ((!$menuLinks) || ($returnAsArray && isset($params['assign']))) {
if (isset($params['assign'])) {
$view->assign($params['assign'], $menuLinks);
- } else {
- return '';
}
+ return '';
}
$html = '';
diff --git a/src/system/Zikula/Module/AdminModule/Resources/views/Admin/adminpanel.tpl b/src/system/Zikula/Module/AdminModule/Resources/views/Admin/adminpanel.tpl
index 1a8d440518..820425fd0f 100644
--- a/src/system/Zikula/Module/AdminModule/Resources/views/Admin/adminpanel.tpl
+++ b/src/system/Zikula/Module/AdminModule/Resources/views/Admin/adminpanel.tpl
@@ -19,7 +19,8 @@
{$adminlink.menutext|safetext}
{assign var="modlinks" value=false}
- {modapifunc modname=$adminlink.modname type='admin' func='getlinks' assign='modlinks'}
+ {*{modapifunc modname=$adminlink.modname type='admin' func='getlinks' assign='modlinks'}*}
+ {modulelinks modname=$adminlink.modname type='admin' assign='modlinks' returnAsArray=true}
{if $modlinks}