2017 © Pedro Peláez
 

silverstripe-module modulator

A SilverStripe module for dynamically creating pages from smaller components

image

touchcast/modulator

A SilverStripe module for dynamically creating pages from smaller components

  • Tuesday, April 11, 2017
  • by touchcast
  • Repository
  • 2 Watchers
  • 0 Stars
  • 4,876 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 15 Versions
  • 1 % Grown

The README.md

SilverStripe Modulator

Travis Packagist Packagist, (*1)

Modulator is an extendable system for creating sub-page components. It achieves this by attaching DataObjects to the page in place of the traditional Content body., (*2)

Features

  • Draft and publish control on a per-module level
  • Drag-and-drop re-ordering of modules
  • An extendable system for creating your own modules
  • CMS previewing
  • Filtering of available modules per page type

Installation

Modulator can be installed via Composer;, (*3)

composer require touchcast/modulator

After installing, run a /dev/build to generate the database tables., (*4)

Usage

Create a ModularPage page within your Site Tree. Add new modules to the page and populate them as required., (*5)

Creating modules

Each module consists of a PHP class and a template file., (*6)

Start by extending PageModule, (*7)

class HeroModule extends PageModule {

  // Give the module a name for use within the CMS
  public static $label = "Hero module";

  // Give it a description
  public static $description = "A large title section at the top of the page";

  // Optionally group your modules by type, for easy reference in the CMS
  public static $category = "Headers";

  // Add any fields required for the module
  private static $db = array(
    "Heading" => "Varchar(128)"
  );

  // Provide custom summary content for the gridfield
  public function getSummaryContent() {
    return $this->Heading;
  }

  // Provide text content from the module to be included in the pages's search index
  public function getSearchBody() {
    return $this->Heading;
  }
}

Next create a template file. It should have the same name as your module class., (*8)

<header>
  <h1>$Heading</h1>
</header>

If you want to extend the ModularPage template, you can render the modules by hand using the $ActiveModules loop., (*9)

<% loop $ActiveModules %>
<section class="$ClassName.Lowercase <% if $Odd %>odd<% else %>even<% end_if %> order-$Order">
  $Content
</section>
<% end_loop %>

Filtering available modules

For each page class you extend from ModularPage you can specify a list of modules which are allowed to be attached to that page. e.g;, (*10)

class CustomPage extends ModularPage {

  public static $allowed_modules = array(
    'HeroModule',
    'TextModule'
  );
}

Custom base modules

If you want to create a custom base class for page modules to contain any common fields, you can specifiy this in a config file;, (*11)

ModularPage:
  base_class: CustomModuleBase

You can take this a step further and specify a different base class for each page type (as an alternative to using $allowed_modules);, (*12)

ModularPage:
  base_class: CustomModuleBase

BlogPage:
  base_class: BlogModuleBase

Search body population

The default behaviour is to populate the SiteTree Content field with the contents of all the page's modules, so that it can be indexed by Silverstripe's built-in search functionality. If you don't want this behaviour you can disable it on a per-class basis;, (*13)

ModularPage:
  write_content: true

BlogPage:
  write_content: false

Testing

Run phpunit from within the module folder, or /dev/tests from the browser., (*14)

The Versions

11/04 2017

dev-master

9999999-dev

A SilverStripe module for dynamically creating pages from smaller components

  Sources   Download

The Requires

 

The Development Requires

by Andrew Joll

11/04 2017

0.14

0.14.0.0

A SilverStripe module for dynamically creating pages from smaller components

  Sources   Download

The Requires

 

The Development Requires

by Andrew Joll

10/04 2017

0.13

0.13.0.0

A SilverStripe module for dynamically creating pages from smaller components

  Sources   Download

The Requires

 

The Development Requires

by Andrew Joll

05/02 2017

0.12

0.12.0.0

A SilverStripe module for dynamically creating pages from smaller components

  Sources   Download

The Requires

 

The Development Requires

by Andrew Joll

20/10 2016

0.11

0.11.0.0

A SilverStripe module for dynamically creating pages from smaller components

  Sources   Download

The Requires

 

The Development Requires

by Andrew Joll

30/06 2016

0.10

0.10.0.0

A SilverStripe module for dynamically creating pages from smaller components

  Sources   Download

The Requires

 

The Development Requires

by Andrew Joll

22/06 2016

0.9

0.9.0.0

A SilverStripe module for dynamically creating pages from smaller components

  Sources   Download

The Requires

 

The Development Requires

by Andrew Joll

02/06 2016

0.8

0.8.0.0

A SilverStripe module for dynamically creating pages from smaller components

  Sources   Download

The Requires

 

The Development Requires

by Andrew Joll

10/05 2016

0.7

0.7.0.0

A SilverStripe module for dynamically creating pages from smaller components

  Sources   Download

The Requires

 

The Development Requires

by Andrew Joll

11/04 2016

0.6

0.6.0.0

A SilverStripe module for dynamically creating pages from smaller components

  Sources   Download

The Requires

 

The Development Requires

by Andrew Joll

08/04 2016

0.5

0.5.0.0

A SilverStripe module for dynamically creating pages from smaller components

  Sources   Download

The Requires

 

The Development Requires

by Andrew Joll

31/03 2016

0.4

0.4.0.0

A SilverStripe module for dynamically creating pages from smaller components

  Sources   Download

The Requires

 

The Development Requires

by Andrew Joll

25/03 2016

0.1

0.1.0.0

A SilverStripe module for dynamically creating pages from smaller components

  Sources   Download

The Requires

 

The Development Requires

by Andrew Joll

25/03 2016

0.2

0.2.0.0

A SilverStripe module for dynamically creating pages from smaller components

  Sources   Download

The Requires

 

The Development Requires

by Andrew Joll

25/03 2016

0.3

0.3.0.0

A SilverStripe module for dynamically creating pages from smaller components

  Sources   Download

The Requires

 

The Development Requires

by Andrew Joll