Skip to content

Creating modules

Ricky edited this page Feb 21, 2022 · 4 revisions

The system has been re-written to use a module based framework for individual features similar to many of the popular content management systems. This is still a work in progress to fully separate out the different aspects of the system. Module configuration is done through JSON files, PHP classes for models and controllers, and templating using Smarty.

Update January 2020: Modules are now split into 2 sections: core and addon. It's fairly self-explanatory, but core modules are the foundations of HamletCMS such as blogs, posts and users and are all included when the project is cloned. Addon modules are created by anyone. Composer can be used to include addon modules in your project see: using composer to install addon modules.

Configuration

Configuration files are placed in the root directory for the module. Note that for changes to take effect module caches must be reloaded - currently this can be done through the terminal by running php app/reloadcaches.php or when logged in as a system admin.

info.json

Provides the basic information on the module - this file is required for the module to be detected by the system.

{
    "name": "Post comments",
    "author": "Ricky",
    "locked": 1,
    "dependencies": [
        
    ]
}

Note - dependencies have not yet been implemented!

routes.json

Define an array of routes, each with a unique key, for paths in format /cms/[controller]/[action]/{BLOG_ID} permissions can be checked automatically to see if the current logged in user has permission to view/action the route.

[
    {
        "key": "posts.create.markdown",
        "path": "/cms/posts/create/{BLOG_ID}/standard",
        "controller": "\\HamletCMS\\MarkdownPost\\controller\\MarkdownPost",
        "action": "create",
        "permissions": ["create_posts"]
    }
]

menu.json

Target menus within the system to add links, currently only route menu type is implemented. Will eventually have external URL support.

[
    {
        "menu": "create_post",
        "type": "route",
        "route": "posts.create.markdown",
        "weight": 10,
        "text": "Markdown post",
        "subtext": "Create a post using markdown code to add formatting.",
        "icon": "wrench"
    }
]

permissions.json

Defines custom permissions for routes within the module.

[
    {
        "key": "change_settings",
       "label": "Change blog settings",
        "group": "settings"
    }
]

Classes

src/controller

PHP files in this directory can be used as controllers

src/model

PHP files in this directory can be used as models

Templates

.tpl files in this folder can be used as templates, templates can be nested in sub-directories.