Silverstripe 4 元素 GroupedDropdownfield inline_editable
Silverstripe 4 Elemental GroupedDropdownfield inline_editable
我的自定义元素扩展
将 GroupedDropdownField 呈现为 select 来自视频 - 数据对象的视频。
这在以下情况下效果很好
inline_editable 设置为 false。
当我尝试将 inline_editable 设置为 true 时,GroupedDropdownField 未呈现。
当 inline_editing 为真时如何显示 GroupedDropdownField?
<?php
use DNADesign\Elemental\Models\BaseElement;
use SilverStripe\Forms\GroupedDropdownField;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\FieldList;
use SilverStripe\ORM\FieldType\DBField;
use SilverStripe\View\HTML;
use SilverStripe\Dev\Debug;
use SilverStripe\Dev\Backtrace;
class VideoElement extends BaseElement
{
private static $singular_name = 'Videoelement';
private static $plural_name = 'Videoelements';
private static $description = 'add a Video';
private static $icon = 'fa fa-video-camera outline mt-1';
private static $table_name = 'VideoElementBlock';
private static $inline_editable = false;
private static $has_one = [
'Video' => VideoObject::class
];
private static $owns = [
'Video',
];
public function getCMSFields()
{
$fields = parent::getCMSFields();
$categories = VideoCatObject::get();
$subcategoryArray = [];
foreach ($categories as $category) {
$subcategoryArray[$category->Title] = $category->Videos()->map('ID', 'Title')->toArray();
}
$fields->addFieldToTab('Root.Main', GroupedDropdownField::create(
'VideoID',
'Video',
$subcategoryArray
));
return $fields;
}
public function getSummary()
{
if ($this->Video() && $this->Video()->exists()) {
return $this->getSummaryThumbnail() . $this->Video()->Title;
}
return '';
}
public function getSummaryThumbnail()
{
$data = [];
if ($this->Video() && $this->Video()->exists()) {
$data['Image'] = $this->Video()->AutoThumbnail()->ScaleWidth(36)->CropHeight(36);
}
return $this->customise($data)->renderWith('VideoElementThumbnail');
}
public function fieldLabels($includerelations = true)
{
$labels = parent::fieldLabels($includerelations);
$labels['EmbeddedObject'] = _t(__CLASS__ . '.EmbeddedObjectLabel', 'Content from oEmbed URL');
return $labels;
}
protected function provideBlockSchema()
{
$blockSchema = parent::provideBlockSchema();
if ($this->Video() && $this->Video()->exists()) {
$blockSchema['fileURL'] = $this->Video()->AutoThumbnail()->getURL();
$blockSchema['fileTitle'] = $this->Video()->getTitle();
}
return $blockSchema;
}
public function getType()
{
return 'Video';
}
}
在撰写本文时,在当前的 Silverstripe CMS Recipe 版本 (4.7.0
) 中,GroupedDropdownField
没有 React 实现,这是 Elemental 内联编辑器支持呈现它所必需的.
不幸的是,目前您需要使用具有 React 实现的不同字段,或者您自己编写。
我的自定义元素扩展 将 GroupedDropdownField 呈现为 select 来自视频 - 数据对象的视频。
这在以下情况下效果很好 inline_editable 设置为 false。
当我尝试将 inline_editable 设置为 true 时,GroupedDropdownField 未呈现。
当 inline_editing 为真时如何显示 GroupedDropdownField?
<?php
use DNADesign\Elemental\Models\BaseElement;
use SilverStripe\Forms\GroupedDropdownField;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\FieldList;
use SilverStripe\ORM\FieldType\DBField;
use SilverStripe\View\HTML;
use SilverStripe\Dev\Debug;
use SilverStripe\Dev\Backtrace;
class VideoElement extends BaseElement
{
private static $singular_name = 'Videoelement';
private static $plural_name = 'Videoelements';
private static $description = 'add a Video';
private static $icon = 'fa fa-video-camera outline mt-1';
private static $table_name = 'VideoElementBlock';
private static $inline_editable = false;
private static $has_one = [
'Video' => VideoObject::class
];
private static $owns = [
'Video',
];
public function getCMSFields()
{
$fields = parent::getCMSFields();
$categories = VideoCatObject::get();
$subcategoryArray = [];
foreach ($categories as $category) {
$subcategoryArray[$category->Title] = $category->Videos()->map('ID', 'Title')->toArray();
}
$fields->addFieldToTab('Root.Main', GroupedDropdownField::create(
'VideoID',
'Video',
$subcategoryArray
));
return $fields;
}
public function getSummary()
{
if ($this->Video() && $this->Video()->exists()) {
return $this->getSummaryThumbnail() . $this->Video()->Title;
}
return '';
}
public function getSummaryThumbnail()
{
$data = [];
if ($this->Video() && $this->Video()->exists()) {
$data['Image'] = $this->Video()->AutoThumbnail()->ScaleWidth(36)->CropHeight(36);
}
return $this->customise($data)->renderWith('VideoElementThumbnail');
}
public function fieldLabels($includerelations = true)
{
$labels = parent::fieldLabels($includerelations);
$labels['EmbeddedObject'] = _t(__CLASS__ . '.EmbeddedObjectLabel', 'Content from oEmbed URL');
return $labels;
}
protected function provideBlockSchema()
{
$blockSchema = parent::provideBlockSchema();
if ($this->Video() && $this->Video()->exists()) {
$blockSchema['fileURL'] = $this->Video()->AutoThumbnail()->getURL();
$blockSchema['fileTitle'] = $this->Video()->getTitle();
}
return $blockSchema;
}
public function getType()
{
return 'Video';
}
}
在撰写本文时,在当前的 Silverstripe CMS Recipe 版本 (4.7.0
) 中,GroupedDropdownField
没有 React 实现,这是 Elemental 内联编辑器支持呈现它所必需的.
不幸的是,目前您需要使用具有 React 实现的不同字段,或者您自己编写。