TYPO3 从 sys_file_reference 获取文件对象

问题描述

我希望能够在后端添加后备视频文件。因此后端用户可以为不支持主要文件格式的浏览器添加不同文件格式的相同视频。 示例:主要视频文件格式是 .webm,次要文件格式是 .mp4。

我已经为 sys_file_reference.PHP 创建了 TCA 覆盖程序

    $temporaryColumn = array(
    'tx_framework_video_fallback' => [
        'label' => 'LLL:EXT:gizmo_framework/Resources/Private/Language/locallang_be.xlf:Pages.videoOptionFallbackVideo.Title','config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig('tx_framework_video_fallback',[
            'appearance' => [
                'createNewRelationLinkTitle' => 'LLL:EXT:gizmo_framework/Resources/Private/Language/locallang_be.xlf:Pages.videoOptionPoster.addPoster'
            ],],//Filter for File Types ex. images
            'mp4,gif,mov')
    ],);

    
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns(
    'sys_file_reference',$temporaryColumn
);



\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addFieldsToPalette(
    'sys_file_reference','videoOverlayPalette','--linebreak--,tx_framework_video_fallback','after:autoplay'
);

这里是 ext_table.sql

CREATE TABLE `sys_file_reference` (
    'tx_framework_video_fallback' int(11) unsigned DEFAULT '0' NOT NULL,);

我通过内容元素排版加载视频

tt_content.textmedia =< lib.contentElement
tt_content.textmedia {
    templateName = Textmedia

    dataProcessing {
        10 = TYPO3\CMS\Frontend\DataProcessing\FilesProcessor
        10 {
            references.fieldName = assets
            }
        20 = TYPO3\CMS\Frontend\DataProcessing\galleryProcessor
        20 {
            maxgalleryWidth = {$styles.content.textmedia.maxW}
            maxgalleryWidthInText = {$styles.content.textmedia.maxWInText}
            columnSpacing = {$styles.content.textmedia.columnSpacing}
            borderWidth = {$styles.content.textmedia.borderWidth}
            borderPadding = {$styles.content.textmedia.borderPadding}
        }
    }
}

到目前为止一切顺利,我可以在后端的内容元素中添加一个视频,它会显示在前端。

但是我无法加载链接到 sys_file_reference 的视频。它被正确保护并添加到 sys_file_reference 表中。

我尝试在内容元素排版的 dataProcessor 中加载后备视频

tt_content.textmedia =< lib.contentElement
tt_content.textmedia {
    templateName = Textmedia

    dataProcessing {
        10 = TYPO3\CMS\Frontend\DataProcessing\FilesProcessor
        10 {
            references.fieldName = assets
            dataProcessing {
                10 = TYPO3\CMS\Frontend\DataProcessing\FilesProcessor
                10{
                    references.table = sys_file_reference
                    references.fieldName = tx_framework_video_fallback
                    as = fallbackMediaReference
                }
            }
        }
        20 = TYPO3\CMS\Frontend\DataProcessing\galleryProcessor
        20 {
            maxgalleryWidth = {$styles.content.textmedia.maxW}
            maxgalleryWidthInText = {$styles.content.textmedia.maxWInText}
            columnSpacing = {$styles.content.textmedia.columnSpacing}
            borderWidth = {$styles.content.textmedia.borderWidth}
            borderPadding = {$styles.content.textmedia.borderPadding}
        }
    }
}

我也尝试过使用 DatabaseQueryProcessor,但我从来没有得到视频的文件对象。

如何设置 dataProcessing 以加载链接到主文件的 sys_file_reference 的辅助文件

感谢您的帮助!

解决方法

由于当前文件处理器中没有额外的 dataProcessing 可用,您将不得不使用自己的自定义数据处理器或创建一个解决方法。

解决方法确实可以基于 DatabaseQueryProcessor,因为这将为您提供 FilesProcessor 中仍然缺少的额外数据处理器。另一方面,您可以在渲染 FilesProcessor 提供的文件列表时使用额外的 FLUIDTEMPLATE 设置。

如果您更喜欢 DatabaseQueryProcessor,则必须使用连接查询来获取必要的文件,这可能会更复杂一些。

https://docs.typo3.org/m/typo3/reference-typoscript/master/en-us/Functions/Select.html

如果您选择额外的 FLUIDTEMPLATE,您可以在渲染主文件列表时使用 f:cObject 视图助手添加它,并将参考记录作为 data 移交。

https://docs.typo3.org/other/typo3/view-helper-reference/9.5/en-us/typo3/fluid/latest/CObject.html

如果您希望在 FilesProcessor 本身内解决该问题,您可能希望支持此问题,该问题已在上一个 TYPO3 倡议周https://forge.typo3.org/issues/88627

,

这是我使用 FLUIDTEMPLATE f:cObject 的回答。感谢 Jo Hasenau 的提示!

希望能帮到遇到同样问题的人。

流体模板.html:

<f:cObject typoscriptObjectPath="lib.fallbackMedia" data="{file}"/>

setup.typoscript

lib.fallbackMedia = FILES
lib.fallbackMedia {
    
    //references the table,field and which uid it should get
    references{
        table = sys_file_reference
        fieldName = tx_framework_video_fallback
        uid.data = uid
    }

    //renders the references as an IMG Resource
    renderObj = COA
    renderObj {
        10 = IMG_RESOURCE
        10 {
            file.import.dataWrap = {file:current:storage}:{file:current:identifier}
            stdWrap.dataWrap = <source src="|" type="{file:current:mime_type}">
        }
    }
}

有关 FILES cObject 的更多信息:https://docs.typo3.org/m/typo3/reference-typoscript/master/en-us/ContentObjects/Files/Index.html

在流体模板中,您现在可以使用多个来源构建 HTML 视频标签。