【问题标题】:Add online video to 'textmedia' element将在线视频添加到“textmedia”元素
【发布时间】:2018-07-17 16:10:12
【问题描述】:

在扩展中,我基本上想做核心在您单击现有 textmedia 元素上的“通过 URL 添加媒体”按钮时所做的事情。

我试图查看源代码,但没有找到任何我可以使用的方便的 API 函数。也许我可以为此使用DataHandler

核心所做的是创建一个包含视频 ID 的文本文件(例如 .youtube)。然后它在 sys_file 中为该文件创建一条记录,并在 tt_content 中的记录和 sys_file 中的文件记录之间创建一个文件引用 (sys_file_reference)。


我正在使用最新的 TYPO3 8。

【问题讨论】:

    标签: typo3 typo3-8.x


    【解决方案1】:

    我没有完整的解决方案,但我最近不得不做类似的事情:

    从视频 URL 创建文件并创建对应的 sys_file 记录:

    1. OnlineMediaController::createAction 类可以满足您的需求。具体来说,OnlineMediaHelperRegistry::transformUrlToFile 函数会将视频 URL 转换为文件(必要时创建文件)。
    2. 要使用现有操作,您可以使用 Ajax 路由online_media_create
    3. 或者,您可以使用现有操作来为您自己的代码建模。

    在 sys_file 和 tt_content 中的现有记录之间创建关系:

    1. 参见Creating a file reference(TYPO3 文档)

    示例代码:(大部分代码取自Creating a file reference

    use TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\OnlineMediaHelperRegistry;
    use TYPO3\CMS\Core\Resource\ResourceFactory;
    use TYPO3\CMS\Backend\Utility\BackendUtility;
    

    ...

    protected function addMediaByUrl($url, $uid)
    {
        $targetFolder = $GLOBALS['BE_USER']->getDefaultUploadFolder();
        $file = OnlineMediaHelperRegistry::getInstance()->transformUrlToFile(
            $url, 
            $targetFolder
        );
        $contentElement = BackendUtility::getRecord('tt_content', $uid);
        $newId = 'NEW1234';
        $data = array();
        $data['sys_file_reference'][$newId] = [
            'table_local' => 'sys_file',
            'uid_local' => $file->getUid(),
            'tablenames' => 'tt_content',
            'uid_foreign' => $contentElement['uid'],
            'fieldname' => 'assets',
            'pid' => $contentElement['pid']
        ];
        $data['tt_content'][$contentElement['uid']] = [
            'assets' => $newId
        ];
        // Get an instance of the DataHandler and process the data
        /** @var DataHandler $dataHandler */
        $dataHandler = GeneralUtility::makeInstance(DataHandler::class);
        $dataHandler->start($data, array());
        $dataHandler->process_datamap();
        // Error or success reporting
        if (count($dataHandler->errorLog) === 0) {
            // Handle success
        } else {
            // Handle error
        }  
    }
    

    【讨论】:

      【解决方案2】:

      也许你在这里寻找好的例子 YoutubeVideo, Vimeo, Video-Files, 更多信息您可以在 vhs 中找到Docs

      或者你可以这样做:

      <flux:form id="youtubevideo" label="YouTubeVideo" description="Einbetten eines 
      YouTube Videos als iframe">
        <flux:form.option name="optionsettings">
          <flux:form.option.group value="Content" />
          <flux:form.option.icon
          value="EXT:extension_key/Resources/Public/Icons/Content/YouTubeVideo.svg" />
        </flux:form.option>
      
        <flux:field.input name="settings.videoid" label="YouTube Video ID. Entnehmen 
        Sie die ID aus der YouTube URL. Beispiel: https://www.youtube.com/watch? 
        v=UX12345678 Die ID ist UX12345678" />
        <flux:field.select name="settings.videoformat" label="Video Format"
        maxItems="1" multiple="0" default="YouTubeVideo--normal" items="{YouTubeVideo-- 
        normal: 'Normal (4:3)', YouTubeVideo--widescreen: 'Widescreen (16:9)'}"/>
        <flux:field.checkbox name="settings.gridPull" label="Bleed Outside (Randlos 
        glücklich)" default="0" />
      </flux:form>
      
      ...
      
      <div class="YouTubeVideo {settings.videoformat}">
        <iframe width="640" height="480" src="//www.youtube- 
        nocookie.com/embed/{settings.videoid}?rel=0&showinfo=0" allowfullscreen>
        </iframe>
      </div>

      【讨论】:

      • 我的问题可能不够清楚:我不想在页面上的某个位置嵌入 YouTube 视频(尽管结果基本上是这样)。我正在为旧的、不再受支持的内容元素编写迁移脚本,其中包含指向 YouTube 视频的 URL。我希望通过引用视频将内容元素转换为“文本媒体”。最终结果应该与某人创建“textmedia”并使用“按 URL 添加媒体”添加 URL 后的结果相同。你的回答很有趣,但我不认为它回答了我的问题。
      【解决方案3】:

      终于找到解决办法了:

      关键是设置正确的“允许的扩展程序”:添加“youtube”或“vimeo”。 这将自动添加缺少的“通过 URL 添加媒体”按钮。

      使用 Flux Inline FAL 的示例:

      <f:section name="Configuration">
          <flux:form id="myCustomVideoContentElement">
              <flux:field.inline.fal name="settings.records" label="video"
               multiple="false" minItems="1" maxItems="1"
               allowedExtensions="mp4,mkv,youtube,vimeo"
              />
          </flux:form>
      </f:section>
      

      (Typo3 9.5)

      【讨论】:

      • 注意:助焊剂不是 TYPO3 核心的一部分。无论如何。看起来是一个不错的解决方案,我会检查一下。谢谢!
      猜你喜欢
      • 2018-01-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-15
      • 1970-01-01
      • 2018-04-02
      相关资源
      最近更新 更多