-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1763 from craigh/routePlugin
add route Zikula_View plugin. refs #1552
- Loading branch information
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |