PHP code example of christopherbolt / silverstripe-contentmodules

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

    

christopherbolt / silverstripe-contentmodules example snippets




use ChristopherBolt\ContentModules\ContentModule;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;

class TextModule extends ContentModule {
		
	private static $db = array(
		'Title' => 'Varchar',
		'Content' => 'HTMLText'
	);
	
	function getCMSFields() {
		$fields = parent::getCMSFields();
		$fields->addFieldsToTab('Root.Main', array(
			TextField::create('Title', 'Title'),
			HTMLEditorField::create('Content', 'Content')
		));		
		return $fields;
	}
}

use ChristopherBolt\ContentModules\ContentModuleArea;
use ChristopherBolt\ContentModules\ModularPageExtension;

class TwoColumnPage extends Page {
	private static $has_one = array(
        "RightColumn" => ContentModuleArea::class
	);
    private static $owns = array(
        "RightColumn"
    );
	private static $extensions = array(
        ModularPageExtension::class
	);
	function getCMSFields() {
		$fields = parent::getCMSFields();
		
		$fields->addFieldsToTab('Root.RightColumn', $this->getModularCMSFields('RightColumn', 'Right Column'));
				
		return $fields;
	}
}