So, falls es sonst noch jemand braucht, hab's jetzt endlich hinbekommen (oder hingepfuscht, Auslegungssache ).
Benutze jetzt das alte ce_downloads.html5 Template statt dem neuen Twig, weil ich damit nicht zurecht komme.
config.php
PHP-Code:
$GLOBALS['TL_CTE']['files']['downloads'] = \Contao\ContentDownloads::class;
src/EventListener/ParseTemplateListener.php
PHP-Code:
<?php
namespace App\EventListener;
use Contao\CoreBundle\DependencyInjection\Attribute\AsHook;
use Contao\CoreBundle\Routing\ScopeMatcher;
use Contao\FilesModel;
use Contao\Template;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
#[AsHook('parseTemplate')]
class ParseTemplateListener
{
private ScopeMatcher $scopeMatcher;
private ?Request $request;
public function __construct(ScopeMatcher $scopeMatcher, RequestStack $requestStack)
{
$this->scopeMatcher = $scopeMatcher;
$this->request = $requestStack->getCurrentRequest();
}
/**
* Add the copyright fields to the image template
*
* @param Template $template
*
* @return void
*/
public function onParseTemplate(Template $template): void
{
if (null === $this->request) {
return;
}
if (false === $this->scopeMatcher->isFrontendRequest($this->request)) {
return;
}
// Only the downloads template should be used
if (false === str_starts_with($template->getName(), 'ce_downloads')) {
return;
}
$files = $template->__get('files');
if(null === $files){
return;
}
foreach($files as $key=>$file) {
$uuid = $file['uuid'];
$fullFile = FilesModel::findByUuid($uuid);
if(null === $fullFile){
return;
}
$categories = $fullFile->filterCategories;
$file['categories'] = $categories;
$files[$key] = $file;
}
$template->__set('files', $files);
}
}
tl_files.php
PHP-Code:
<?php
use Contao\CoreBundle\DataContainer\PaletteManipulator;
$GLOBALS['TL_DCA']['tl_files']['fields']['filterCategories'] = [
'label' => &$GLOBALS['TL_LANG']['tl_files']['filterCategories'],
'inputType' => 'text',
'sql' => ['type' => 'string', 'default' => ''],
];
PaletteManipulator::create()
->addField('filterCategories', 'meta', PaletteManipulator::POSITION_APPEND)
->applyToPalette('default', 'tl_files');