PHP code example of arillo / silverstripe-elements

1. Go to this page and download the library: Download arillo/silverstripe-elements 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/ */

    

arillo / silverstripe-elements example snippets


class Element extends ElementBase
{
    private static
        $singular_name = 'Base element',
        $db = [
            'Title' => 'Text',
            'Subtitle' => 'Text',
            ...
            ..
            .
        ]
    ;
}

$pageInst->ElementsByRelation('Elements');
$elementInst->ElementsByRelation('Elements');

public function getCMSFields()
{
    $fields = parent::getCMSFields();
    // move the elements gridfield to a tab called 'PageElements'..
    $fields = ElementsExtension::move_elements_manager($fields, 'Elements', 'Root.PageElements');
    return $fields;
}

use Arillo\Elements\BulkUploader;

public function getCMSFields()
    {
        $fields = parent::getCMSFields();
        if ($images = $fields->dataFieldByName('Images')) {
            BulkUploader::apply(
                $images,
                [
                    BulkUploader::ELEMENT_CLASSNAME => ImageElement::class,
                    BulkUploader::ELEMENT_RELATIONNAME => 'Images',
                    BulkUploader::FOLDER_NAME => 'FancyFolderName', // optional
                    BulkUploader::FILE_RELATIONNAME => 'File',  // optional, may be mandatory if you element has multiple has_one file relations
                ]
            );
        }
        return $fields;
    }