Skip to content
michael-lefebvre edited this page Apr 7, 2013 · 3 revisions

Tapioca Documents's hooks

Tapioca provide a hook mechanism that allows you to perform operations on every step on the document creation/update.

These hooks are defined in the collection's schema and responds to an event.

Hook definition

    "hooks": 
    {
        "document::before": 
            [
                "Season::interval",
                "Season::category"
            ],
        "status::after": 
            [
                "Season::status",
                "http://mywebsite.com/path/to/service"
            ]
    }

These exemple will call the method interval in Season class just before document is created or updated.

Hook class

The classes are stored in the hooks/[app-slug]/classes folder.

When the method is call, the hook provide the full document content, plus for the status hooks, the document current status.

You must always return $document.

Hooks are based on FuelPHP's modules so you can referrer to the manual for more information about.

    <?php

    namespace APP-SLUG;

    class Season
    {
        public static function _init()
        {
            // call every time 
            // useful to set global params
        }

        public static function interval( $document )
        {
            // you own logic..

            return $document;
        }

        // [...]

        public static function status( $document, $status )
        {
            // you own logic..

            return $document;
        }
    }

Hook URL (beta)

You can call an URL, this will send a cURL resquest in POST.

Events list

hook Description
document::before before any create/update
document::before::new before create a new document
document::after::new after create a new document
document::before::update before update a document
document::after::update after update a document
document::after after any create/update
status::before before change document status
status::after after change document status

Clone this wiki locally