heimrichhannot/contao-youtube-bundle

此包已废弃,不再维护。作者建议使用 https://github.com/heimrichhannot/contao-video-bundle 包。

支持响应式的 YouTube 内容元素,预览图片,播放按钮等。


README

Build Status Coverage Status

YouTube-Bundle 已不再积极维护,因为我们开发了后续的包: 视频包

YouTube 包旨在提供具有预览图片和更好的隐私控制的响应式 YouTube 视频。它支持内容元素和新闻条目。

需要有效的 YouTube 数据 API 密钥 以支持自动预览图片(在 Contao 系统设置或根页面上输入)。

如果您从 heimrichhannot/contao-youtube 升级,请参阅 升级通知

特性

  • 响应式 YouTube 视频
  • YouTube 视频的预览图片
    • 如果没有提供自定义图片,预览图片将从 YouTube 加载并保存到 'files/media/youtube/'
  • List-Readerbundle 提供 ConfigElements。
  • Encore Bundle 支持
  • 隐私模式
    • 在隐私模式下,视频将在用户在接受模态提示中的隐私建议后显示
    • 用户可以通过复选框将其选择标记为永久(状态将保存在cookie中)

alt privacy modal

技术说明

添加到列表和阅读器条目模板

对于与 List-Readerbundle 一起使用,您首先需要在 List- 和/或 Reader 配置中添加配置元素。

之后,您可以将 YouTube 添加到模板中。配置元素添加了一个格式化的值 youtubeVideos,其中包含由配置元素添加的每个 YouTube 字段的数组。

$templateData = [
    // ...
    'youtubeVideos' => [
        'youtubeField' => [ // The selected youtube field name from config element
            'video' => '' // Generated default template,
            'data' => [] // Video data for custom templates
        ]
    ]
]

示例自定义模板

{% if raw.addYouTube == "1" and youtubeVideos.youtube|default%}
    {% include '@VendorMyBundle/youtube/youtube_video_custom.html.twig' with youtubeVideos.youtube.data %}
{% endif %}

新闻模板

可以轻松地将 YouTube 视频添加到新闻模板中。只需添加以下代码(例如:news_full.html5)

<?php if($this->youtube && $this->youtube->video): ?>
	<?= $this->youtube->video; ?>
<?php endif; ?>

YouTube 的预览图片

要使用 YouTube 的预览图片,您必须生成一个 API 密钥 (https://developers.google.com/youtube/v3/getting-started) 并将其放置在 Contao 设置中。

命令

迁移命令

Usage:
  huh:youtube:migration [options]

Options:
      --dry-run              Performs a run without writing to database.
      --migration=MIGRATION  Do migration directly without interrupt. Options: module, database, both, none
  -h, --help                 Display this help message
  -q, --quiet                Do not output any message
  -V, --version              Display this application version
      --ansi                 Force ANSI output
      --no-ansi              Disable ANSI output
  -n, --no-interaction       Do not ask any interactive question
  -e, --env=ENV              The Environment name. [default: "prod"]
      --no-debug             Switches off debug mode.
  -v|vv|vvv, --verbose       Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Help:
  This command provide migration scripts to migrate from heimrichhannot/contao-youtube to heimrichhannot/contao-youtube-bundle.
  
  Available migrations:
    'module' updates default template names and field values
    'database' updates database fields that can't be updated by the contao install tool.
    'both' will run 'module' and 'database' migrations.

开发者

事件

事件 事件ID
与AlertifyJs的'显示'事件交互的事件 huh.youtube.event.alertify.onshow
与AlertifyJs的'聚焦'事件交互的事件 huh.youtube.event.alertify.onfocus

从heimrichhannot/contao-youtube的升级通知

  • 使用huh:youtube:migration命令迁移根页面和relatedYoutubeNews数据库字段中的默认模板设置
  • 在tl_settings或tl_page中声明一个YouTube-API密钥(否则预览图片下载将无法工作)
  • 隐私对话框或模态视频的模态窗口需要额外的CSS,该CSS由包本身不提供。标记符合Bootstrap模态窗口CSS,因此建议使用该框架的CSS。
  • 如果您使用的是自定义的YouTube .html5模板,需要将它们迁移到.html.twig模板,如需帮助,请检查默认模板