public static function addFilesBreadcrumb($strKey = 'tl_files_node')
{
/** @var AttributeBagInterface $objSession */
$objSession = \System::getContainer()->get('session')->getBag('contao_backend');
// Set a new node
if (isset($_GET['fn'])) {
// Check the path (thanks to Arnaud Buchoux)
if (\Validator::isInsecurePath(\Input::get('fn', true))) {
throw new \RuntimeException('Insecure path ' . \Input::get('fn', true));
}
$objSession->set($strKey, \Input::get('fn', true));
\Controller::redirect(preg_replace('/(&|\\?)fn=[^&]*/', '', \Environment::get('request')));
}
$strNode = $objSession->get($strKey);
if ($strNode == '') {
return;
}
// Check the path (thanks to Arnaud Buchoux)
if (\Validator::isInsecurePath($strNode)) {
throw new \RuntimeException('Insecure path ' . $strNode);
}
// Currently selected folder does not exist
if (!is_dir(TL_ROOT . '/' . $strNode)) {
$objSession->set($strKey, '');
return;
}
$objUser = \BackendUser::getInstance();
$strPath = \Config::get('uploadPath');
$arrNodes = explode('/', preg_replace('/^' . preg_quote(\Config::get('uploadPath'), '/') . '\\//', '', $strNode));
$arrLinks = array();
// Add root link
$arrLinks[] = \Image::getHtml('filemounts.svg') . ' <a href="' . \Backend::addToUrl('fn=') . '" title="' . \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['selectAllNodes']) . '">' . $GLOBALS['TL_LANG']['MSC']['filterAll'] . '</a>';
// Generate breadcrumb trail
foreach ($arrNodes as $strFolder) {
$strPath .= '/' . $strFolder;
// Do not show pages which are not mounted
if (!$objUser->hasAccess($strPath, 'filemounts')) {
continue;
}
// No link for the active folder
if ($strPath == $strNode) {
$arrLinks[] = \Image::getHtml('folderC.svg') . ' ' . $strFolder;
} else {
$arrLinks[] = \Image::getHtml('folderC.svg') . ' <a href="' . \Backend::addToUrl('fn=' . $strPath) . '" title="' . \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['selectNode']) . '">' . $strFolder . '</a>';
}
}
// Check whether the node is mounted
if (!$objUser->hasAccess($strNode, 'filemounts')) {
$objSession->set($strKey, '');
throw new AccessDeniedException('Folder ID "' . $strNode . '" is not mounted');
}
// Limit tree
$GLOBALS['TL_DCA']['tl_files']['list']['sorting']['root'] = array($strNode);
// Insert breadcrumb menu
$GLOBALS['TL_DCA']['tl_files']['list']['sorting']['breadcrumb'] .= '
<ul id="tl_breadcrumb">
<li>' . implode(' > </li><li>', $arrLinks) . '</li>
</ul>';
}