Hauer-Heinrich / hh_video_extender

TYPO3 extension. Extends sys_file_reference video/media. Added attributes to select in content element (eg textmedia)
0 stars 4 forks source link

How could I get the preview image with its metadata via dataProcessing? #37

Open zenoussi opened 1 year ago

zenoussi commented 1 year ago

Hello together, to output image credits at the end of a page, I use the following code for ce textmedia:

`lib.photocredits = FLUIDTEMPLATE lib.photocredits {

[...]

dataProcessing {

Bildnachweis: CE Textmedia

10 = TYPO3\CMS\Frontend\DataProcessing\DatabaseQueryProcessor
10 {
  table = tt_content
  where.data = field:uid
  orderBy = sorting
  as = myrecords
  dataProcessing {
   10 = TYPO3\CMS\Frontend\DataProcessing\FilesProcessor
   10 {
     references.fieldName = assets
     as = image
   }
 }

} }

Fluid-Ausgabe:

{image.properties.copyright}`

This works for videos and images and would need to add the preview image to it. I hope someone can help me with this.

Thanks a lot Ulli

Teisi commented 1 year ago

Sry i don't know how we can nest the dataProcessing thing correctly. But you can try to use a custom viewhelper like this one below:

<?php
namespace HauerHeinrich\HhVideoExtender\ViewHelpers;

/***************************************************************
 * Copyright notice
 *
 * (c) 2023 Christian Hackl
 * All rights reserved
 *
 * This script is part of the TYPO3 project. The TYPO3 project 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.
 *
 * The GNU General Public License can be found at
 * http://www.gnu.org/copyleft/gpl.html.
 *
 * This script 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.
 *
 * This copyright notice MUST APPEAR in all copies of the script!
 * Example
 * <html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
 *   xmlns:hhve="http://typo3.org/ns/HauerHeinrich/HhVideoExtender/ViewHelpers"
 *   data-namespace-typo3-fluid="true">
 *
 *  <hhve:getPreviewImage as="previewImage" uid="154" />
 */

// use \TYPO3\CMS\Extbase\Utility\DebuggerUtility;
use \TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use \TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
use \TYPO3\CMS\Core\Utility\GeneralUtility;

class GetPreviewImageViewHelper extends AbstractViewHelper {
    public function initializeArguments() {
        $this->registerArgument('as', 'string', 'The name of the iteration variable', false, 'hhvideoextender');
        $this->registerArgument('uid', 'int', 'Uid of the file / media which has the preview image attached.', false);
    }

    /**
     * @param array $arguments
     * @param \Closure $renderChildrenClosure
     * @param RenderingContextInterface $renderingContext
     *
     * @return string
     */
    public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) {
        $templateVariableContainer = $renderingContext->getVariableProvider();
        $uid = $arguments['uid'];

        if(empty($uid) || !\is_numeric($uid)) {
            return '';
        }

        $fileRepository = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\FileRepository::class);
        $fileObjects = $fileRepository->findByRelation('sys_file_reference', 'preview_image', $uid);

        $output = '';
        $templateVariableContainer->add($arguments['as'], $fileObjects);
        $output .= $renderChildrenClosure();

        return $output;
    }
}