PHP code example of bummzack / page-blocks

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

    

bummzack / page-blocks example snippets



class BlockPage extends Page
{
    private static $description = 'A page with several content-blocks';
    
    private static $extensions = array(
        'PageBlocks'
    );
}

class BlockPage_Controller extends Page_Controller
{
    
}

public function getCMSFields()
{
    $fields = parent::getCMSFields();

    // get the Blocks GridField
    if ($blocks = $fields->fieldByName('Root.Main.Blocks')) {
        // Restrict the types of blocks that can be added to this page
        $blocks->getConfig()->setAllowedBlocks(array(
            'ImageBlock', 'TextBlock'
        ));
    }

    return $fields;
}



class EmbedBlock extends Block
{
    private static $db = array(
        'EmbedCode' => 'Text'
    );
    
    public function getCMSFields()
    {
        $fields = parent::getCMSFields();
        $fields->addFieldToTab('Root.Main', 
            new TextareaField('EmbedCode', 'Embed code'));
        $this->extend('updateCMSFields', $fields); // be nice to extensions
        return $fields;
    }
}