• Stars
    star
    109
  • Rank 319,077 (Top 7 %)
  • Language
    PHP
  • License
    BSD 3-Clause "New...
  • Created about 10 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Create pages in Silverstripe CMS using content blocks

Silverstripe CMS Elemental

CI Silverstripe supported module

Introduction

This module extends a page type to swap the content area for a list of manageable elements to compose a page out of rather than a single text field. Features supported:

  • Versioning of elements
  • Ability to add, remove supported elements per elemental area

The module provides basic markup for each of the elements but you will likely need to provide your own styles. Replace the $Content variable with $ElementalArea in your page templates, and rely on the markup of the individual elements.

For a more detailed overview of using this module, please see the User help guides.

Requirements

  • Silverstripe CMS ^5.0
  • Versioned Admin ^2.0
  • GridFieldExtensions ^4.0

For a CMS 4.3+ compatible version of this module, please see the 4.x release line.

For a Silverstripe CMS 4.1 or 4.2 compatible version of this module, please see the 2.x or 3.x release line.

Installation

composer require dnadesign/silverstripe-elemental

composer require dnadesign/silverstripe-elemental


The following YAML config will enable elements on every `Page` object,
replacing the standard `Content` rich text field.

**mysite/_config/elements.yml**

```yaml
Page:
  extensions:
    - DNADesign\Elemental\Extensions\ElementalPageExtension

In your page type layout template use $ElementalArea to render the elements to the page (in place of $Content).

Getting more elements

Note that this module comes by default with the base element and a "Content" element. If you need more, take a look at some other modules:

Silverstripe CMS supported content block modules

To learn more about Silverstripe CMS supported content block types see, Creating new blocks.

Examples of community built content block modules (not a comprehensive list - may not be updated for Elemental 4 yet)

  • dnadesign/silverstripe-elemental-list: Container for elements (allows layouts)
  • dnadesign/silverstripe-elemental-virtual: Reuse elements across pages
  • dynamic/silverstripe-elemental-blocks: Elemental Blocks will add the following Elements to your site
    • Accordion: content in collapsable panels
    • Countdown: time left until a set date and time
    • Customer Service: map, directions, and contact info for your location
    • Embeded Code: embed code like iframes, javascript
    • Featured Content: large image, headline, description, link. one per row
    • File List: A list of files for download
    • Flexslider: Flexslider slideshow
    • Gallery: display a collection of images
    • Image: single image
    • oEmbed: embed content from YouTube, SoundCloud, etc
    • Promos: small image, headline, description, link. 3 to 4 per row
    • Recent Blog Posts: list of the most recent posts of a specific blog
    • Section Navigation: list of child pages or pages in current level
    • Sponsors: sponsor logos in a row
    • Tab Set: Create a tabbed interface that uses elements
    • Testimonials: list of customer testimonials, filter by category

Helpful modules

These modules can extend functionality, and make elemental more compatible with other approaches in Silverstripe CMS:

Configuration

Limit to specific page type

If you want to use elements alongside traditional page types, you can define an "empty" page type and assign the extension only to this type.

mysite/src/MyElementPage.php

<?php
class MyElementPage extends Page
{
}

mysite/_config/elements.yml

MyElementPage:
  extensions:
    - DNADesign\Elemental\Extensions\ElementalPageExtension

Migrating existing page content

You can use the MigrateContentToElement BuildTask that is provided to assist with migrating content from pages to elements. For more information on using this task refer to the content migration documentation.

Customize HTML and markup

The basic element area is rendered into the DNADesign/Elemental/Models/ElementalArea.ss template. This loops over each of the element controller instances. Each controller instance will render $ElementHolder which represents the element contained within a holder div. The wrapper div is the ElementHolder.ss template.

To customise the ElementEditor in the CMS you will need to use the Silverstripe CMS JS Injector to apply transformations to the necessary React components. See here for more information.

Limit allowed elements

You may wish to only enable certain elements for the CMS authors to choose from rather than the full set. This can be done according to various page types:

Page:
  allowed_elements:
    - DNADesign\Elemental\Models\ElementContent

Likewise, you can exclude certain elements from being used.

Page:
  disallowed_elements:
    - YourCompany\YourModule\Elements\ElementContact

Sharing elements between pages

By default the page to element relationship is a "has one", meaning you cannot share elements between pages. If this functionality is desired, you could take a look at the silverstripe-elemental-virtual module which helps to achieve this.

Defining your own elements

An element is as simple as a PHP class which extends DNADesign\Elemental\Models\BaseElement, and a template to go with it (unless you want it to use the default template). After you add the class, ensure you have rebuilt your database and reload the CMS.

The getSummary() method will be used to provide a short summary to content authors of what data is in the element.

<?php

use DNADesign\Elemental\Models\BaseElement;

class MyElement extends BaseElement
{
    private static $singular_name = 'my element';

    private static $plural_name = 'my elements';

    private static $description = 'What my custom element does';

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

        // ...

        return $fields;
    }

    public function getSummary(): string
    {
        return /* some string that represents the data in this element */;
    }

    public function getType()
    {
        return 'My Element';
    }
}

In-line Editing

Elements can be edited in the CMS using an inline form where all your elements appear together. For elements that are more complex (e.g. use custom FormField classes) you can disable the in-line edit form by setting private static $inline_editable = false in your element class. A GridFieldDetailForm will be used to edit blocks that are not in-line editable. Alternatively as the CMS element editor is now React driven, in-line editing functionality can be added to by defining your own React components.

Note: The default is that all elements are in-line editable.

If in-line editing is not disabled, whilst not having a custom component defined, custom fields will not be rendered unless the field's schemaDataType is set See Framework's FormField definition.

After building your own React components and including them into the CMS, altering the applicable Element's PHP definition to use the new React component can be achieved by setting some protected properties of that class.

    protected $schemaDataType = FormField::SCHEMA_DATA_TYPE_CUSTOM;
    protected $schemaComponent = 'BlockLinkField';
  • The $schemaDataType does not need to be CUSTOM, but should not be STRUCTURAL as structural types are not submitted as form data.
  • The $schemaComponent is the name of the React component you have created to be used.

The above example was taken from silverstripe/elemental-bannerblock

Defining your own HTML

MyElement will be rendered into a MyElement.ss template with the ElementHolder.ss wrapper. Changing the holder template can be done via YAML, or by using a $controller_template on your subclass.

private static $controller_template = 'MyElementHolder';

To customise existing block templates such as Content and Form templates, copy the relevant files from vendor/dnadesign/silverstripe-elemental/templates to your theme. When doing this, ensure you match the folder structure (PHP class namespace) to ensure that your new template version takes priority.

Note: The default set of elements follow the [BEM (Block Element Modifier])(http://getbem.com/) class naming convention, which allows developers to style individual parts of the DOM without unnecessarily nested CSS. Where possible, we encourage you to follow this naming system.

Position Helpers

In your BaseElement template you can use the following variables for additional logic or styling helpers. They behave in the same way traditional SS_Viewer methods work either returning a Boolean, String or a Int

  1. $First (boolean)
  2. $Last (boolean)
  3. $Pos (int)
  4. $TotalItems (int)
  5. $EvenOdd (string - 'even' or 'odd')
<div class="element element--{$EvenOdd} <% if First %>element--first<% end_if %> <% if Last %>element--last<% end_if %>">
    // ...
</div>

Style variants

Via YAML you can configure a whitelist of style variants for each BaseElement subclass. For instance, if you have dark and light variations of your content block you would enter the following in YAML in the format (class: 'Description'). The class will be added to the ElementHolder.

DNADesign\Elemental\Models\ElementContent:
  styles:
    light: 'Light Background'
    dark: 'Dark Background'

Disabling the default stylesheets

When installing this module, there may be a default set of CSS stylesheets that come to provide some examples for the various default element types for the front-end website.

You can disable this with YAML configuration:

# File: mysite/_config/elements.yml
DNADesign\Elemental\Controllers\ElementController:
  include_default_styles: false

Implementing search

The Elemental module comes with an indexer for Solr (via the silverstripe-fulltextsearch module). You can enable this index in your search engine to ensure that a page's elemental area content is indexed under the page's data.

For information on configuring Solr please see the fulltextsearch documentation.

Note: If using this indexer, be aware that HTML tags will be stripped from the content before it is indexed. The Solr search results may add in emphasis tags or other formatting around matched key words, so you may need to allow unescaped HTML in your search results template. You should use the $Excerpt property (see SolrIndex::search for more) to display the relevant search matches.

Disabling CMS content search

When installing this module, the page model admin search will look for a term in the entire content of each elemental pages. This is done by rendering each page, which can be resource hungry and make the search timeout.

You can disable this with YAML configuration:

# File: mysite/_config/elements.yml
DNADesign\Elemental\Controllers\ElementSiteTreeFilterSearch:
  search_for_term_in_content: false

Usage of GridField

This module used to use GridField to create and update Elements in the CMS. This has now been largely succeeded by a JavaScript interface via React. However elements that are marked as being incompatible with in-line editing will still use the GridField method.

Building the elemental frontend assets

This module uses the Silverstripe CMS Webpack module, and inherits things from the core Silverstripe CMS modules, such as a core variable sheet and Javascript components.

When making changes to either the SASS or Javascript files, ensure you change the source files in client/src/.

You can have yarn watch and rebuild delta changes as you make them (for development only):

yarn watch

When you're ready to make a pull request you can rebuild them, which will also minify everything. Note that watch will generate source map files which you shouldn't commit in for your final pull request. To minify and package:

yarn build

You'll need to have yarn installed globally in your command line.

Note: If adding or modifying colours, spacing, font sizes etc. please try and use an appropriate variable from the silverstripe/admin module if available.

Integration with other modules

Screenshots

Elemental content block overview

Versioning

This library follows Semver. According to Semver, you will be able to upgrade to any minor or patch version of this library without any breaking changes to the public API. Semver also requires that we clearly define the public API for this library.

All methods, with public visibility, are part of the public API. All other methods are not part of the public API. Where possible, we'll try to keep protected methods backwards-compatible in minor/patch versions, but if you're overriding methods then please test your work before upgrading.

Reporting Issues

Please create an issue for any bugs you've found, or features you're missing.

Credits

Silverstripe Elemental was created by DNA Design.

CMS Icon blocks by Creative Stall from the Noun Project.

More Repositories

1

silverstripe-framework

Silverstripe Framework, the MVC framework that powers Silverstripe CMS
PHP
720
star
2

silverstripe-cms

Silverstripe CMS - this is a module for Silverstripe Framework rather than a standalone app. Use https://github.com/silverstripe/silverstripe-installer/ to set this up.
PHP
508
star
3

doorman

Child process management
PHP
317
star
4

silverstripe-installer

The installer for Silverstripe CMS and Framework. Check out this repository to start working with Silverstripe!
Twig
163
star
5

silverstripe-userforms

UserForms module provides a visual form builder for the Silverstripe CMS. No coding required to build forms such as contact pages.
PHP
135
star
6

silverstripe-blog

Blog module for SilverStripe CMS
PHP
105
star
7

silverstripe-subsites

Subsites module for SilverStripe CMS
PHP
62
star
8

silverstripe-tagfield

SilverStripe module for editing tags (both in the CMS and other forms)
PHP
58
star
9

silverstripe-translatable

Translatable extension for SilverStripe CMS
PHP
56
star
10

silverstripe-graphql

Serves Silverstripe data as GraphQL representations
PHP
52
star
11

sspak

Tool for managing bundles of db/assets from Silverstripe environments
PHP
46
star
12

silverstripe-staticpublishqueue

This module allows you to build static HTML caches of every page (for increased security and performance)
PHP
45
star
13

silverstripe-restfulserver

RestfulServer module for SilverStripe CMS
PHP
43
star
14

silverstripe-fulltextsearch

Adds external full text search engine support to SilverStripe
PHP
43
star
15

silverstripe-spamprotection

Spam protection module for SilverStripe CMS
PHP
42
star
16

silverstripe-comments

Adds commenting functionality for Pages and other DataObjects on your Silverstripe site.
PHP
42
star
17

silverstripe-dms

Adds a Document Management System to SilverStripe
PHP
41
star
18

silverstripe-simple

The "Simple" theme for Silverstripe CMS by Sara (Innovaif). Winner of the 2012 theme competition.
CSS
41
star
19

silverstripe-omnipay

Silverstripe integration with Omnipay PHP payments library.
PHP
39
star
20

silverstripe-upgrader

A tool to help upgrade your code to handle API changes in packages you used.
PHP
39
star
21

silverstripe-widgets

Widgets subsystem for SilverStripe CMS
PHP
38
star
22

silverstripe-redirectedurls

Silverstripe module to let users to configure arbitrary redirections in the CMS
PHP
32
star
23

silverstripe-environmentcheck

A Silverstripe module that provides an API for creating environment checks
PHP
32
star
24

silverstripe-multiform

Multi-step form module for SilverStripe
PHP
30
star
25

silverstripe-staticpublisher

Contains extensions for generating a static export of your SilverStripe site.
PHP
27
star
26

silverstripe-module

A skeleton for the Silverstripe CMS supported module standard including useful default documentation
JavaScript
27
star
27

silverstripe-selectupload

Extension to UploadField which allows folder selection prior to uploading
PHP
26
star
28

silverstripe-populate

Populate your database through YAML files
PHP
26
star
29

silverstripe-activedirectory

Adds Active Directory support to SilverStripe including user synchronisation and SSO/LDAP authentication
PHP
26
star
30

silverstripe-admin

Silverstripe Admin Component
JavaScript
25
star
31

silverstripe-crontask

Easily setup tasks to be run by using cron expressions
PHP
23
star
32

silverstripe-serve

Connects the PHP development server to Silverstripe
PHP
22
star
33

silverstripe-contentreview

Mark a page in SilverStripe CMS with a date and an owner for future review
PHP
22
star
34

silverstripe-s3

Silverstripe module to store assets in S3 rather than on the local filesystem (SS4/SS5 only)
PHP
20
star
35

silverstripe-docsviewer

Documentation generator that powers doc.silverstripe.org and your own projects
PHP
20
star
36

silverstripe-lessons-v4

The source code for the SilverStripe.org Lessons section, version 4.x
JavaScript
20
star
37

recipe-cms

Silverstripe recipe for fully featured page and asset content editing
PHP
20
star
38

one-ring-rentals

The source code for the One Ring Rentals tutorial site
CSS
19
star
39

silverstripe-mathspamprotection

PHP
19
star
40

silverstripe-sharedraftcontent

Share draft page content with non-CMS users
PHP
19
star
41

silverstripe-asset-admin

Silverstripe assets gallery for asset management
JavaScript
19
star
42

silverstripe-login-forms

Login form templates for Silverstripe CMS
SCSS
19
star
43

silverstripe-frameworktest

SilverStripe Framework Test
PHP
18
star
44

silverstripe-gatsby

Provides a GraphQL API that allows Gatsby to use your SilverStripe CMS as a data source
PHP
17
star
45

silverstripe-secureassets

SilverStripe module that adds access restrictions to folders in assets, similar to the way you secure pages
PHP
17
star
46

silverstripe-postgresql

PostgreSQL module for SilverStripe CMS. Allows SilverStripe to connect to, and use PostgreSQL as a database.
PHP
16
star
47

silverstripe-hybridsessions

Hybrid Cookie / DB Session store for SilverStripe
PHP
16
star
48

webpack-config

Reusable webpack bundle declarations for Silverstripe modules
JavaScript
16
star
49

silverstripe-html5

Further HTML 5 support for SilverStripe.
PHP
15
star
50

silverstripe-multiuser-editing-alert

CSS
15
star
51

silverstripe-mssql

Microsoft SQL Server module for SilverStripe CMS. Allows SilverStripe to connect to, and use SQL Server as a database.
PHP
15
star
52

doc.silverstripe.org

The source code that powers http://doc.silverstripe.org
JavaScript
14
star
53

silverstripe-graphql-devtools

Tools to help developers building new applications on Silverstripe’s GraphQL API
PHP
14
star
54

addons.silverstripe.org

Website hosting Silverstripe Framework extensions
Less
13
star
55

multi-domain

Allows multiple domains to access one CMS instance, mapping them to different sections of the hierarchy
PHP
13
star
56

cwp-watea-theme

A more visually appealing example for starting a theme for a CWP website.
SCSS
13
star
57

silverstripe-travis-support

Creates a SilverStripe project "around" a module, based on core version constraints and its composer.json definitions
PHP
13
star
58

silverstripe-versioned-snapshots

Tracks version history and modification state in DataObject ownership structures
PHP
13
star
59

silverstripe-auditor

PHP
11
star
60

silverstripe-mfa

MultiFactor Authentication for Silverstripe CMS
PHP
11
star
61

silverstripe-routewhitelist

Provides a whitelist of known valid URL patterns in a SilverStripe website.
PHP
11
star
62

recipe-plugin

Helper plugin to install Silverstripe recipes
PHP
11
star
63

bambusa-installer

SilverStripe demo application
PHP
11
star
64

silverstripe-controllerpolicy

PHP
11
star
65

gatsby-source-silverstripe

Use Silverstripe CMS as a data source for GatsbyJS
TypeScript
10
star
66

silverstripe-superglue

PHP
10
star
67

cwp

Common Web Platform (CWP) features module. We strongly recommend using it for all new CWP projects. Future features will be delivered here.
PHP
10
star
68

silverstripe-gridfieldqueuedexport

Export large data sets from your GridField in the Silverstripe CMS interface through async jobs
PHP
10
star
69

silverstripe-mimevalidator

Checks uploaded file content roughly matches a known MIME type for the file extension.
PHP
10
star
70

silverstripe-assets

Silverstripe Assets component
PHP
9
star
71

silverstripe-securityreport

"Users, Groups and Permissions" report in Silverstripe CMS
PHP
9
star
72

silverstripe-config

Silverstripe CMS configuration based on YAML and class statics
PHP
9
star
73

silverstripe-sitebanner

Create site-wide alerts in the CMS
PHP
9
star
74

silverstripe-realme

PHP
9
star
75

silverstripe-taxonomy

Provides the capability to add and edit simple taxonomies within SilverStripe
PHP
9
star
76

silverstripe-versioned-admin

Provides admin UIs for versioned DataObjects in Silverstripe CMS.
PHP
9
star
77

cwp-agencyextensions

Provides extra CWP functionality for self-managed agency style websites
PHP
9
star
78

silverstripe-textextraction

Text Extraction API for SilverStripe CMS (mostly used with 'fulltextsearch' module)
PHP
9
star
79

silverstripe-session-manager

Allow users to manage and revoke access to multiple login sessions across devices.
PHP
9
star
80

silverstripe-segment-field

PHP
8
star
81

silverstripe-registry

PHP
8
star
82

silverstripe-versioned

Versioning for Silverstripe model
PHP
8
star
83

silverstripe-documentconverter

Imports OpenOffice-compatible files (doc, docx, etc) into Silverstripe pages and content
PHP
7
star
84

silverstripe-content-notifier

The content notifier module use for auditing user-submitted content on the ss.org site
Scheme
7
star
85

silverstripe-siteconfig

Site wide settings administration
PHP
6
star
86

silverstripe-raygun

Raygun.com integration for PHP
PHP
6
star
87

github-issue-search-client

UI for searching Github issues across supported modules (aka Elvis)
Vue
6
star
88

silverstripe-ckan-registry

JavaScript
6
star
89

bambusa-theme

SCSS
6
star
90

silverstripe-totp-authenticator

Provides a TOTP-based authentication method for the Silverstripe MFA module.
JavaScript
6
star
91

silverstripe-nextjs-starter

A starter kit for NextJS projects powered by Silverstripe CMS
TypeScript
6
star
92

silverstripe-headless

Provides headless features for Silverstripe CMS
PHP
6
star
93

developer-docs

Developer documentation for Silverstripe CMS
6
star
94

silverstripe-saml

SAML authentication support module for Silverstripe
PHP
6
star
95

vendor-plugin

Allows Silverstripe vendor modules to expose directories to the webroot
PHP
5
star
96

silverstripe-iframe

PHP
5
star
97

silverstripe-versioned-snapshot-admin

An administrative UI for the versioned-snapshots module
JavaScript
5
star
98

silverstripe-search-service

A service-agnostic search module for Silverstripe CMS
PHP
5
star
99

silverstripe-colorpicker

Colour picker with configurable colours and a React component for Silverstripe CMS
JavaScript
5
star
100

silverstripe-reports

API for creating backend reports in the SilverStripe Framework.
PHP
5
star