public static function generateFrontendUrl(array $arrRow, $strParams = null, $strForceLang = null, $blnFixDomain = false)
{
@trigger_error('Using Controller::generateFrontendUrl() has been deprecated and will no longer work in Contao 5.0. Use the contao.routing.url_generator service or PageModel::getFrontendUrl() instead.', E_USER_DEPRECATED);
if (!isset($arrRow['rootId'])) {
$row = \PageModel::findWithDetails($arrRow['id']);
$arrRow['rootId'] = $row->rootId;
foreach (array('domain', 'rootLanguage', 'rootUseSSL') as $key) {
if (!isset($arrRow[$key])) {
$arrRow[$key] = $row->{$key};
}
}
}
$arrParams = [];
// Set the language
if ($strForceLang != '') {
$arrParams['_locale'] = $strForceLang;
} elseif (isset($arrRow['rootLanguage'])) {
$arrParams['_locale'] = $arrRow['rootLanguage'];
} elseif (isset($arrRow['language']) && $arrRow['type'] == 'root') {
$arrParams['_locale'] = $arrRow['language'];
} elseif (TL_MODE == 'FE') {
/** @var PageModel $objPage */
global $objPage;
$arrParams['_locale'] = $objPage->rootLanguage;
}
// Add the domain if it differs from the current one (see #3765 and #6927)
if ($blnFixDomain) {
$arrParams['_domain'] = $arrRow['domain'];
$arrParams['_ssl'] = (bool) $arrRow['rootUseSSL'];
}
$objUrlGenerator = \System::getContainer()->get('contao.routing.url_generator');
$strUrl = $objUrlGenerator->generate(($arrRow['alias'] ?: $arrRow['id']) . $strParams, $arrParams);
// Remove path from absolute URLs
if (0 === strpos($strUrl, '/')) {
$strUrl = substr($strUrl, strlen(\Environment::get('path')) + 1);
}
// Decode sprintf placeholders
if (strpos($strParams, '%') !== false) {
$arrMatches = array();
preg_match_all('/%([sducoxXbgGeEfF])/', $strParams, $arrMatches);
foreach (array_unique($arrMatches[1]) as $v) {
$strUrl = str_replace('%25' . $v, '%' . $v, $strUrl);
}
}
// HOOK: add custom logic
if (isset($GLOBALS['TL_HOOKS']['generateFrontendUrl']) && is_array($GLOBALS['TL_HOOKS']['generateFrontendUrl'])) {
foreach ($GLOBALS['TL_HOOKS']['generateFrontendUrl'] as $callback) {
$strUrl = static::importStatic($callback[0])->{$callback[1]}($arrRow, $strParams, $strUrl);
}
}
return $strUrl;
}