url global substitution

This commit is contained in:
Etienne Roudeix
2013-08-30 14:30:33 +02:00
parent 4ba16dc290
commit 3c71aa613f
15 changed files with 126 additions and 166 deletions

View File

@@ -90,7 +90,8 @@ class FeatureValue extends BaseLoop
$this->request->getSession()->getLocale(),
array('TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM'),
FeatureAvTableMap::TABLE_NAME,
'FEATURE_AV_ID'
'FEATURE_AV_ID',
true
);
$feature = $this->getFeature();

View File

@@ -40,11 +40,7 @@ class ParserContext implements \IteratorAggregate
public function __construct(Request $request)
{
// Setup basic variables
$this
->set('BASE_URL' , ConfigQuery::read('base_url', '/'))
->set('INDEX_PAGE' , URL::getIndexPage())
->set('RETURN_TO_URL' , URL::absoluteUrl($request->getSession()->getReturnToUrl()))
->set('THELIA_VERSION' , ConfigQuery::read('thelia_version', 'undefined'))
$this->set('THELIA_VERSION' , ConfigQuery::read('thelia_version', 'undefined'))
;
}

View File

@@ -47,14 +47,15 @@ class UrlGenerator extends AbstractSmartyPlugin
public function generateUrlFunction($params, &$smarty)
{
// the path to process
$path = $this->getParam($params, 'path');
$path = $this->getParam($params, 'path');
$target = $this->getParam($params, 'target', null);
$target = $this->getParam($params, 'target', null);
$url = URL::absoluteUrl($path, $this->getArgsFromParam($params, array('path', 'target')));
$url = URL::absoluteUrl($path, $this->getArgsFromParam($params, array('path', 'target')));
if ($target != null) $url .= '#'.$target;
return $url;
if ($target != null) $url .= '#'.$target;
return $url;
}
/**
@@ -81,6 +82,15 @@ class UrlGenerator extends AbstractSmartyPlugin
return $this->generateViewUrlFunction($params, true);
}
public function navigateToUrlFunction($params, &$smarty)
{
$to = $this->getParam($params, 'to', null);
$toMethod = $this->getNavigateToMethod($to);
return $this->$toMethod();
}
protected function generateViewUrlFunction($params, $forAdmin)
{
// the view name (without .html)
@@ -125,7 +135,50 @@ class UrlGenerator extends AbstractSmartyPlugin
return array(
new SmartyPluginDescriptor('function', 'url', $this, 'generateUrlFunction'),
new SmartyPluginDescriptor('function', 'viewurl', $this, 'generateFrontViewUrlFunction'),
new SmartyPluginDescriptor('function', 'admin_viewurl', $this, 'generateAdminViewUrlFunction')
new SmartyPluginDescriptor('function', 'admin_viewurl', $this, 'generateAdminViewUrlFunction'),
new SmartyPluginDescriptor('function', 'navigate', $this, 'navigateToUrlFunction'),
);
}
/**
* @return array sur le format "to_value" => "method_name"
*/
protected function getNavigateToValues()
{
return array(
"current" => "getCurrentUrl",
"return_to" => "getReturnToUrl",
"index" => "getIndexUrl",
);
}
protected function getNavigateToMethod($to)
{
if($to === null) {
throw new \InvalidArgumentException("Missing 'to' parameter in `navigate` substitution.");
}
$navigateToValues = $this->getNavigateToValues();
if(!array_key_exists($to, $navigateToValues)) {
throw new \InvalidArgumentException("Incorrect value for parameter `to` in `navigate` substitution.");
}
return $navigateToValues[$to];
}
protected function getCurrentUrl()
{
return URL::retrieveCurrent($this->request);
}
protected function getReturnToUrl()
{
return URL::absoluteUrl($this->request->getSession()->getReturnToUrl());
}
protected function getIndexUrl()
{
return Url::getIndexPage();
}
}