elementsilverstripeinline-editing

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 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';
    }
}

Solution

  • 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.