Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

element - Silverstripe 4 Elemental GroupedDropdownfield inline_editable

My custom Elemental Extension renders a GroupedDropdownField to select a Video from a Video - Dataobject.

This works well when inline_editable is set to false.

When i try to set inline_editable to true, the GroupedDropdownField is not rendered.

How can i display the GroupedDropdownField when inline_editing is true?

<?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';
    }
}
question from:https://stackoverflow.com/questions/65861480/silverstripe-4-elemental-groupeddropdownfield-inline-editable

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

At the time of writing, in the current Silverstripe CMS Recipe version (4.7.0), GroupedDropdownField does not have a React implementation, which is required for the Elemental inline editor to support rendering it.

Unfortunately, for the time being you'll need to use a different field that has a React implementation, or write this yourself.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...