diff --git a/Classes/EventListener/AddFurtherMetadataToFile.php b/Classes/EventListener/AddFurtherMetadataToFile.php new file mode 100644 index 0000000..a7f2307 --- /dev/null +++ b/Classes/EventListener/AddFurtherMetadataToFile.php @@ -0,0 +1,60 @@ + + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +use TYPO3\CMS\Core\Resource\Event\EnrichFileMetaDataEvent; +use TYPO3\CMS\Core\Resource\FileReference; +use TYPO3\CMS\Frontend\Resource\FileCollector; + +class AddFurtherMetadataToFile +{ + /** + * @var FileCollector + */ + private $fileCollector; + + public function __construct(FileCollector $fileCollector) + { + $this->fileCollector = $fileCollector; + } + + public function __invoke(EnrichFileMetaDataEvent $event): void + { + $record = $event->getRecord(); + + $record['poster'] = $this->resolvePoster($record); + + $event->setRecord($record); + } + + private function resolvePoster(array $record): ?FileReference + { + $this->fileCollector->addFilesFromRelation( + 'sys_file_metadata', + 'poster', + $record + ); + + $files = $this->fileCollector->getFiles(); + return $files[0] ?? null; + } +} diff --git a/Configuration/Services.yaml b/Configuration/Services.yaml index 87d99d8..633e48d 100644 --- a/Configuration/Services.yaml +++ b/Configuration/Services.yaml @@ -28,3 +28,12 @@ services: iconIdentifier: 'content-widget-rss' height: 'medium' width: 'small' + + # Events + DanielSiepmann\DsSite\EventListener\AddFurtherMetadataToFile: + public: true + tags: + - name: event.listener + identifier: 'AddFurtherMetadataToFile' + event: TYPO3\CMS\Core\Resource\Event\EnrichFileMetaDataEvent + after: 'languageAndWorkspaceOverlay' diff --git a/Configuration/TCA/Overrides/sys_file_metadata.php b/Configuration/TCA/Overrides/sys_file_metadata.php new file mode 100644 index 0000000..db7c127 --- /dev/null +++ b/Configuration/TCA/Overrides/sys_file_metadata.php @@ -0,0 +1,35 @@ + + [ + 'youtube' => [ + 'label' => $languagePath . 'youtube', + 'config' => [ + 'type' => 'input', + 'eval' => 'trim', + ], + ], + 'poster' => [ + 'label' => $languagePath . 'poster', + 'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig( + 'poster', + [ + 'maxitems' => 1, + ], + $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'] + ), + ], + ], + ]); + + \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes( + $tableName, + 'youtube, poster', + '', + 'after:title' + ); +})('ds_site', 'sys_file_metadata'); diff --git a/Configuration/TCA/Overrides/tt_content.php b/Configuration/TCA/Overrides/tt_content.php index 766bd79..ba097a9 100644 --- a/Configuration/TCA/Overrides/tt_content.php +++ b/Configuration/TCA/Overrides/tt_content.php @@ -1,7 +1,7 @@ [ $ctype => [ 'showitem' => implode(',', [ diff --git a/Configuration/TCA/Overrides/tt_content_image.php b/Configuration/TCA/Overrides/tt_content_image.php index f51d168..89af2a0 100644 --- a/Configuration/TCA/Overrides/tt_content_image.php +++ b/Configuration/TCA/Overrides/tt_content_image.php @@ -1,7 +1,7 @@ [ $ctype => [ 'showitem' => implode(',', [ diff --git a/Resources/Private/Language/locallang_tca.xlf b/Resources/Private/Language/locallang_tca.xlf index a0d3941..109f2f1 100644 --- a/Resources/Private/Language/locallang_tca.xlf +++ b/Resources/Private/Language/locallang_tca.xlf @@ -12,6 +12,13 @@ Video + + + YouTube key of Video + + + Poster Image before Video is loaded + diff --git a/Resources/Private/Partials/Video.html b/Resources/Private/Partials/Video.html index 125a444..9904087 100644 --- a/Resources/Private/Partials/Video.html +++ b/Resources/Private/Partials/Video.html @@ -1,15 +1,18 @@
-
diff --git a/Resources/Private/Templates/Backend/ContentElements/Video.html b/Resources/Private/Templates/Backend/ContentElements/Video.html index aad6073..ec7d10b 100644 --- a/Resources/Private/Templates/Backend/ContentElements/Video.html +++ b/Resources/Private/Templates/Backend/ContentElements/Video.html @@ -11,9 +11,28 @@
+

Video v{video.originalFile.uid}: {video.title}

- Video v{video.originalFile.uid}: {video.title}
- {video.description -> f:format.nl2br()} + + + The Video is available on YouTube: https://www.youtube.com/watch?v={video.properties.youtube}. + + + The Video is not available on YouTube + + +

+

{video.description -> f:format.nl2br()}

+ +

+ + + + + + No poster configured. + +

diff --git a/ext_tables.sql b/ext_tables.sql index 8401104..d775a4d 100644 --- a/ext_tables.sql +++ b/ext_tables.sql @@ -1,3 +1,8 @@ CREATE TABLE sys_category ( slug varchar(2048), ); + +CREATE TABLE sys_file_metadata ( + youtube varchar(255) DEFAULT '' NOT NULL, + poster int(11) unsigned DEFAULT '0' NOT NULL, +);