将在线视频添加到 'textmedia' 元素

Add online video to 'textmedia' element

在扩展中,当您单击现有 textmedia 元素上的按钮 "Add media by URL" 时,我基本上想做核心所做的事情。

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

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


我用的是最新的TYPO3 8.

也许你在这里寻找好的例子 YoutubeVideo, Vimeo, Video-Files, More Informations you can find at the 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>

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

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

  1. class OnlineMediaController::createAction does what you are looking for. Specifically, the function 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
    }  
}

终于找到解决方案:

关键是设置正确的“允许扩展名”:添加"youtube"或"vimeo"。 这将自动添加缺少的 "Add media by 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>

(打字错误 9.5)