Skip to content

Instantly share code, notes, and snippets.

@dogawaf
Created October 7, 2018 11:56
Show Gist options
  • Save dogawaf/6eeb2be9cfc307081c3d3ca2163e4108 to your computer and use it in GitHub Desktop.
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
<?php
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content.php']['typoLink_PostProc'][]
= \Site\Site\Hooks\TypolinkFileHandler::class . '->wrapFileLink';
<?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)";
}
}
}
@dogawaf
Copy link
Author

dogawaf commented Oct 7, 2018

This typolink hook add to any file link the extension and the weight of the downloadable file.

Compatible with TYPO3 8.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment