Created
October 7, 2018 11:56
-
-
Save dogawaf/6eeb2be9cfc307081c3d3ca2163e4108 to your computer and use it in GitHub Desktop.
Overrides typolink to add file's extension and weight to the generated link
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content.php']['typoLink_PostProc'][] | |
= \Site\Site\Hooks\TypolinkFileHandler::class . '->wrapFileLink'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Site\Site\Hooks; | |
class TypolinkFileHandler | |
{ | |
/** | |
* @param array $params | |
* @param \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $parentObject | |
*/ | |
public function wrapFileLink($params, $parentObject) | |
{ | |
if ($params['linkDetails']['type'] === 'file' && $params['linkDetails']['file'] instanceof \TYPO3\CMS\Core\Resource\File) { | |
$sizeLabel = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_fluid.']['_LOCAL_LANG.']['fr.']['viewhelper.format.bytes.units']; | |
$sizeLabel = str_replace(',', '| ', $sizeLabel); | |
/* @var $file \TYPO3\CMS\Core\Resource\File */ | |
$file = $params['linkDetails']['file']; | |
$ext = strtolower($file->getExtension()); | |
$size = $parentObject->stdWrap_bytes($file->getSize(), ['bytes.' => ['labels' => $sizeLabel]]); | |
$params['linktxt'] .= " ($ext - $size)"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This typolink hook add to any file link the extension and the weight of the downloadable file.
Compatible with TYPO3 8.7