PHP code example of plato-creative / sections

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

    

plato-creative / sections example snippets


class MyCustomPage extends Page
{
    private static $extensions = array(
        'Sectioned'
    )
}

class MyCustomPage extends Page
{
    private static $extensions = array(
        'Sectioned'
    )

    private static $areas = array(
        'Sections' => 'Sections' // make sure you add standard sections area in other it will be deleted
        'OtherSections' => 'Other sections cms title'
    )
}

class MyCustomPage extends Page
{
    private static $extensions = array(
        'Sectioned'
    )

    private static $allowed_sections = array(
        'ContentSection',
        'BannerSection'
    )
}

class MyCustomPage extends Page
{
    private static $extensions = array(
        'Sectioned'
    )

    private static $exclude_sections = array(
        'FormSection'
    )
}

class MyCustomSection extends Section
{
    // Defines the name used in the cms such as a new dropdown and gridfield type.
    private static $singular_name = 'My custom name';
    private static $plural_name = 'Sections';

    // Define db fields
    private static $db = array(
        'Content' => 'HTMLText'
    );

    // Define a list db fields that can be searched via the frontend
    private static $site_searchable_fields = array(
        'Content'
    );

    // Defines available layouts for this section selectable in the cms
    private static $layouts = array(
        'left-text' => 'Left text',
        'right-text' => 'Right text',
        'center' => 'Center',
    );

    // Defines available color schemes for this section selectable in the cms
    private static $colors = array(
        'black' => 'White text on black',
        'blue' => 'White text on blue background'
    );

    // Defines a custom css class for this section
    private static $base_class = 'my-custom-css-class';

    // Defines if the title of the section will be forced to hide from public display.
    private static $title_force_hide = true;

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

class MyCustomSectionController extends SectionController
{
    private static $allowed_actions = array(
        'Form'
    );

    public function Form(){
        $fields = FieldList::create(array(
            TextField::create('Name'),
            EmailField::create('Email'),
            TextField::create('Phone'),
            TextAreaField::create('Message')
        ));
        $actions = FieldList::create(
            FormAction::create('submit', 'Send Enquiry')
        );
        return Form::create($this, 'Form', $fields, $actions);
    }

    public function submit($data, $form){
        // process form data as usual
        // ...
        // redirect
        return $this->redirect($this->CurrentPage->Link() . '?contacted=1');
    }
}