Source of file TestimonialWidgetPageExtension.php

Size: 0,953 Bytes - Last Modified: 2021-12-23T10:11:29+00:00

/var/www/docs.ssmods.com/process/src/TestimonialWidgetPageExtension.php

12345678910111213141516171819202122232425262728293031323334353637
<?php

class TestimonialWidgetPageExtension extends DataExtension
{
    private static $many_many = array(
        'Widgets' => 'Widget'
    );

    private static $many_many_extraFields = array(
        'Widgets' => array(
            'WidgetOrder' => 'Int'
        )
    );

    public function updateCMSFields(FieldList $fields)
    {
        $widgetGrid = GridField::create(
            "Widgets",
            "Widgets",
            $this->GetWidgets(),
            GridFieldConfig_RecordEditor::create()
                ->removeComponentsByType("GridFieldAddNewButton")
                ->addComponent(new GridFieldAddNewMultiClass())
                ->addComponent(new GridFieldOrderableRows('WidgetOrder'))
        );

        $fields->addFieldToTab(
            "Root.Widgets", $widgetGrid
        );
    }

    public function GetWidgets()
    {
        return $this->getOwner()->getManyManyComponents('Widgets', '', 'WidgetOrder ASC');
    }
}