public static function getURLForBlock($module, $action = null, $language = null, array $data = null)
{
$module = (string) $module;
$action = $action !== null ? (string) $action : null;
$language = $language !== null ? (string) $language : BackendLanguage::getWorkingLanguage();
$pageIdForURL = null;
$navigation = self::getNavigation($language);
$dataMatch = false;
// loop types
foreach ($navigation as $level) {
// loop level
foreach ($level as $pages) {
// loop pages
foreach ($pages as $pageId => $properties) {
// only process pages with extra_blocks that are visible
if (!isset($properties['extra_blocks']) || $properties['hidden']) {
continue;
}
// loop extras
foreach ($properties['extra_blocks'] as $extra) {
// direct link?
if ($extra['module'] == $module && $extra['action'] == $action && $extra['action'] !== null) {
// if there is data check if all the requested data matches the extra data
if (isset($extra['data']) && $data !== null && array_intersect_assoc($data, (array) $extra['data']) !== $data) {
// It is the correct action but has the wrong data
continue;
}
// exact page was found, so return
return self::getURL($properties['page_id'], $language);
}
if ($extra['module'] == $module && $extra['action'] == null) {
// if there is data check if all the requested data matches the extra data
if (isset($extra['data']) && $data !== null) {
if (array_intersect_assoc($data, (array) $extra['data']) !== $data) {
// It is the correct module but has the wrong data
continue;
}
$pageIdForURL = (int) $pageId;
$dataMatch = true;
}
if ($extra['data'] === null && $data === null) {
$pageIdForURL = (int) $pageId;
$dataMatch = true;
}
if (!$dataMatch) {
$pageIdForURL = (int) $pageId;
}
}
}
}
}
}
// still no page id?
if ($pageIdForURL === null) {
return self::getURL(404, $language);
}
$url = self::getURL($pageIdForURL, $language);
// set locale with force
FrontendLanguage::setLocale($language, true);
// append action
if ($action !== null) {
$url .= '/' . urldecode(FrontendLanguage::act(\SpoonFilter::toCamelCase($action)));
}
// return the unique URL!
return $url;
}