public static function createURLForAction($action = null, $module = null, $language = null, array $parameters = null, $urlencode = true)
{
// redefine variables
$action = $action !== null ? (string) $action : null;
$module = $module !== null ? (string) $module : null;
$language = $language !== null ? (string) $language : BackendLanguage::getWorkingLanguage();
$queryString = '';
// checking if we have an url, because in a cronjob we don't have one
if (self::getContainer()->has('url')) {
// grab the URL from the reference
$url = self::getContainer()->get('url');
// redefine
if ($action === null) {
$action = $url->getAction();
}
if ($module === null) {
$module = $url->getModule();
}
}
// error checking
if ($action === null || $module === null) {
throw new \Exception('Action and Module must not be empty when creating an URL.');
}
// lets create underscore cased module and action names
$module = mb_strtolower(preg_replace('/([a-z])([A-Z])/', '$1_$2', $module));
$action = mb_strtolower(preg_replace('/([a-z])([A-Z])/', '$1_$2', $action));
// add offset, order & sort (only if not yet manually added)
if (isset($_GET['offset']) && !isset($parameters['offset'])) {
$parameters['offset'] = (int) $_GET['offset'];
}
if (isset($_GET['order']) && !isset($parameters['order'])) {
$parameters['order'] = (string) $_GET['order'];
}
if (isset($_GET['sort']) && !isset($parameters['sort'])) {
$parameters['sort'] = (string) $_GET['sort'];
}
// add at least one parameter
$parameters['token'] = self::getToken();
// add parameters
$i = 1;
foreach ($parameters as $key => $value) {
// first element
if ($i == 1) {
$queryString .= '?' . $key . '=' . ($urlencode ? rawurlencode($value) : $value);
} else {
$queryString .= '&' . $key . '=' . ($urlencode ? rawurlencode($value) : $value);
}
++$i;
}
// build the URL and return it
return self::get('router')->generate('backend', array('_locale' => $language, 'module' => $module, 'action' => $action)) . $queryString;
}