Creating a module - adampatterson/Tentacle GitHub Wiki

Intorcuction

Tentacle has a really great hook and filter system that the great guys over at Chyrp built. Modules can take full advantage of all core features in Tentacle.

Minimum required files

Every module must have these two files to start, there must be a php file with the same name as the folder its in.

  • {module_name}/info.yaml
  • {module_name}/{module_name}.php

The info.yaml file must contain valid YAML and should have the following meta data.

info.yaml

name: Module Name
url: http://tentaclecms.com
version: 1.0
description: Tentacles core Module
author:
  name: Adam Patterson
  url: http://adampatterson.ca

This information is displayed in the admin/settings_modules/ page

{module_name}.php

This is the brains of the whole operation, Everything your plugin does will be controlled here.

First we need to create a class that matches the modules name.

class {module_name} extends Modules {..

You can now create two functions, One called __init() which is a magic method and the onther being the function you want to trigger {function_name}. Both must be public functions so that they can be called from external files.

Any time the {module_name}.php file is loaded the __init() function is called. Lets add $this->addAlias("preview","{function_name}");.

$this->addAlias is part of the hooks and triggers available in Tentacle, the hook "preview" will trigger {function_name}.

As a note, Functions called through aliases must return a value. Think them as a path or stream, without passing the data on the path is blocked.

This of course is up to your discretion.

Read more on the triggers available Triggers.

<?php
class {module_name} extends Modules {

    public function __init() {
        $this->addAlias("preview","{function_name}");
        // Code block
    }

    public function {function_name}() {
        // Code block
        return $something;
    }
}