Created
August 7, 2020 10:18
-
-
Save spoonerWeb/41f37acf918efb8e6cc625ac37300d10 to your computer and use it in GitHub Desktop.
Revisions
-
spoonerWeb created this gist
Aug 7, 2020 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,45 @@ <?php namespace Vendor\Package\EventListener; /* * This file is part of a TYPO3 extension. * * It is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License, either version 2 * of the License, or any later version. * * For the full copyright and license information, please read the * LICENSE.txt file that was distributed with this source code. * * The TYPO3 project - inspiring people to share! */ use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\Utility\GeneralUtility; class AddCategoriesToFile { public function __invoke(\TYPO3\CMS\Core\Resource\Event\EnrichFileMetaDataEvent $event): void { $record = $event->getRecord(); if ($record['categories'] > 0) { $record['categoryRecords'] = $this->getCategories($event->getMetaDataUid()); } $event->setRecord($record); } protected function getCategories(int $metaDataUid): ?array { $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_file_metadata'); return $queryBuilder ->select('*') ->from('sys_category', 'cat') ->leftJoin('cat', 'sys_category_record_mm', 'catmm', 'catmm.uid_local = cat.uid') ->where( $queryBuilder->expr()->eq('catmm.uid_foreign', $metaDataUid) ) ->execute() ->fetchAll(); } } This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ tt_content { own_element =< lib.contentElement own_element { templateName = OwnElement dataProcessing { 10 = TYPO3\CMS\Frontend\DataProcessing\FilesProcessor 10 { references.fieldName = assets as = file } } } } This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,6 @@ <!-- Output a list of all categories --> <f:if condition="{file.0.properties.categoryRecords}"> <f:for each="{file.0.properties.categoryRecords}" as="category" iteration="it"> <f:if condition="{it.isFirst}"><f:else>, </f:else></f:if>{category.title} </f:for> </f:if> This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ services: Vendor\Package\EventListener\AddCategoriesToFile: tags: - name: event.listener identifier: 'AddCategoriesToFile' event: TYPO3\CMS\Core\Resource\Event\EnrichFileMetaDataEvent after: 'languageAndWorkspaceOverlay'