Skip to content

Commit

Permalink
Merge pull request #1763 from craigh/routePlugin
Browse files Browse the repository at this point in the history
add route Zikula_View plugin. refs #1552
  • Loading branch information
Drak committed Jun 14, 2014
2 parents e9bc2f9 + 25c87d5 commit d8ebc1c
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions src/lib/legacy/viewplugins/function.route.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
/**
* Copyright Zikula Foundation 2014 - Zikula Application Framework
*
* This work is contributed to the Zikula Foundation under one or more
* Contributor Agreements and licensed to You under the following license:
*
* @license GNU/LGPLv3 (or at your option, any later version).
* @package Zikula_View
* @subpackage Template_Plugins
*
* Please see the NOTICE file distributed with this source code for further
* information regarding copyright and licensing.
*/
/**
* Zikula_View function to create a compatible route for a specific module function.
*
* NOTE: This function only works for modules using the Core 1.4.0+ routing specification
*
* This function returns a module route string if successful. This is already sanitized to display,
* so it should not be passed to the safetext modifier.
*
* Available parameters:
* - name: the route name e.g. `acmewidgetmakermodule_user_construct`
* - absolute: whether to generate an absolute URL
* - assign: If set, the results are assigned to the corresponding variable instead of printed out
* - all remaining parameters are passed to the generator as route parameters
*
* Example
* Create a route to the News 'view' function with parameters 'sid' set to 3
* <a href="{route name='zikulanewsmodule_user_display' sid='3'}">Link</a>
*
* @param array $params All attributes passed to this function from the template.
* @param Zikula_View $view Reference to the Zikula_View object.
*
* @return string The route.
*/
function smarty_function_route($params, Zikula_View $view)
{
$assign = isset($params['assign']) ? $params['assign'] : null;
unset($params['assign']);
$name = isset($params['name']) ? $params['name'] : false;
unset($params['name']);
$absolute = isset($params['absolute']) ? $params['absolute'] : false;
unset($params['absolute']);

/** @var $router \JMS\I18nRoutingBundle\Router\I18nRouter */
$router = $view->getContainer()->get('router');
$route = $router->generate($name, $params, $absolute);

if ($assign) {
$view->assign($assign, $route);
} else {
return DataUtil::formatForDisplay($route);
}
}

0 comments on commit d8ebc1c

Please sign in to comment.