PHP code example of syntro / silverstripe-elemental-baseitem

1. Go to this page and download the library: Download syntro/silverstripe-elemental-baseitem library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

syntro / silverstripe-elemental-baseitem example snippets


use Syntro\SilverStripeElementalBaseitem\Model\BaseItem;

class Teaser extends BaseItem
{
    private static $displays_title_in_template = true;

    private static $db = [
        // Whatever you need for the item to render
    ];

    private static $has_one = [
        'Section' => TeaserCardsBlock::class,
    ];
}

use DNADesign\Elemental\Models\BaseElement;
use Syntro\SilverStripeElementalBaseitem\Forms\GridFieldConfig_ElementalChildren;

class TeaserCardsBlock extends BaseElement
{
    private static $has_many = [
        'Teasers' => Teaser::class
    ];

    /**
     * @return FieldList
     */
    public function getCMSFields()
    {
        $this->beforeUpdateCMSFields(function ($fields) {
            if ($this->ID) {
                /** @var GridField $griditems */
                $griditems = $fields->fieldByName('Root.Teasers.Teasers');
                $griditems->setConfig(GridFieldConfig_ElementalChildren::create());
            }
        });
        return parent::getCMSFields();
    }
}