nathancox/embedfield

用于向页面或数据对象添加oembed对象的表单字段(主要是视频)

安装次数: 10,065

依赖项: 0

建议者: 0

安全性: 0

星级: 4

关注者: 4

分支: 9

类型:silverstripe-vendormodule

3.0.0 2024-03-22 16:33 UTC

This package is auto-updated.

Last update: 2024-08-25 16:30:10 UTC


README

此字段旨在允许用户将oembed对象(例如YouTube视频)附加到页面或数据对象。它将oembed结果信息存储在EmbedObject中,以便从模板(或您希望的位置)轻松访问。

工作进行中。

要求

  • SilverStripe 4.11+ 或 5.x

文档

GitHub

安装说明

  1. 使用composer安装 composer require nathancox/embedfield
  2. 访问您的网站.com/dev/build以重建数据库

使用概述

创建一个与EmbedObject的has_one关系,然后在getCMSFields中创建一个EmbedField

namespace {

    use SilverStripe\CMS\Model\SiteTree;
    use nathancox\EmbedField\Model\EmbedObject;
    use nathancox\EmbedField\Forms\EmbedField;

    class Page extends SiteTree
    {
        private static $db = [];

        private static $has_one = [
            'MyVideo' => EmbedObject::class
        ];
        
        public function getCMSFields() {
            $fields = parent::getCMSFields();
            
            $fields->addFieldToTab('Root.Main', EmbedField::create('MyVideoID', 'Sidebar video'));
            
            return $fields;
        }
    }
}

给我们

example embedfield

在页面模板中,现在可以使用$MyVideo嵌入视频。

每种嵌入类型都使用自己的模板进行渲染(例如EmbedObject_video.ss和EmbedObject_photo.ss)。默认模板仅返回由SilverStripe的OembedResult::forTemplate()生成的标记。您可以在主题中覆盖它们

themes/mytheme/templates/nathancox/EmbedField/Model/EmbedObject_video.ss

	<div class='flex-video self-sizing' style='padding-bottom:$AspectRatioHeight;'>
		$EmbedHTML
	</div>

这可以与您自己的CSS结合使用,以创建自适应宽高比的灵活视频(请参阅http://alistapart.com/article/creating-intrinsic-ratios-for-video)。

已知问题

问题跟踪器