If we want to share code it is important to develop in a modular way. 

Thinking modular means ensuring features are developed as discrete units of work that together create a set of generic functionality. Exactly how big or small these are is up to the individual development team. It is a good idea to think about how these features might be reused in future projects or how they could be combined with other modules to create further functionality.

For example, the Silverstripe CMS blog functionality has a central blog module with standardised publishing features such as having an author and publishing date. This module itself does not manage comments. There is a separate comment module which can be included alongside the blog module. These two modules together create a full blogging functionality of publishing and commenting.

As the comments module is separate it can easily be used for other purposes where commenting is needed. Similarly the blog module could be reused when comments are not needed.

Golden Rule:  When code is broken down into smaller, modular parts they become easier to share and maintain, and they become more interchangeable.

Importance of being modular

Projects on the CWP should be thought of as a set of components made up of

  • Silverstripe CMS core
  • Modules
  • Bespoke project customisations,
  • Themes
  • Configuration layer consisting of database and other sensitive credentials (which are pre-installed the CWP).

All these components are brought together using the code management tool, 'Composer'.

Composer manages the set of code installed in the project by inspecting a meta data file stored within the project code that states which modules to install and which versions should be used. Using composer allows new modules from the open source community and themes to be installed, and unused modules removed from the project easily, while ensuring the correct code is deployed to the CWP servers.

Note: There are some mandatory packages required for Silverstripe CMS projects running on the CWP which are important to include in public sector CWP projects to make use of the provided shared services.

Golden Rule: Avoid modifying the Silverstripe CMS core or any of the open source modules directly.  The Silverstripe CMS community has developed best practice techniques to extend the functionality of the CMS while ensuring they can benefit from future upgrades.

Using composer and following the golden rule will allow for easy Silverstripe CMS core upgrades when new versions are released. Full testing after all upgrades is still recommended.

Last modified: