Silverstripe 4 Elemental GroupedDropdownfield inline_editabl



我的自定义元素扩展渲染GroupedDropdownField来从视频数据对象中选择视频。

当Inline_editable设置为false

当我尝试将inline_editable设置为true时,GroupedDropdownField不呈现。

如何显示GroupedDropdownField当inline_editing为真?

<?php
use DNADesignElementalModelsBaseElement;
use SilverStripeFormsGroupedDropdownField;
use SilverStripeFormsTextField;
use SilverStripeFormsFieldList;
use SilverStripeORMFieldTypeDBField;
use SilverStripeViewHTML;
use SilverStripeDevDebug;
use SilverStripeDevBacktrace;
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实现,这是element内联编辑器支持渲染所必需的。

不幸的是,目前你需要使用一个有React实现的不同字段,或者自己编写。

相关内容

  • 没有找到相关文章

最新更新