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.

<?phpnamespaceAPP-SLUG;
class Season
{
publicstaticfunction_init()
{
// call every time // useful to set global params
}
publicstaticfunctioninterval( $document )
{
// you own logic..return$document;
}
// [...]publicstaticfunctionstatus( $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

hookDescription
document::beforebefore any create/update
document::before::newbefore create a new document
document::after::newafter create a new document
document::before::updatebefore update a document
document::after::updateafter update a document
document::afterafter any create/update
status::beforebefore change document status
status::afterafter change document status

Clone this wiki locally