-
Notifications
You must be signed in to change notification settings - Fork 310
Plugins
There is going to be a few changes in plugin development from v1.3.2. Information below only applies to v1.3.1. To learn more about the next version, read the migration guide.
From book.cakephp.org: CakePHP allows you to set up a combination of controllers, models, and views and release them as a packaged application plugin that others can use in their CakePHP applications.
You can find a list of plugins available for download here.
- Log in to your admin panel
- Go to
Extensions > Plugins
page - Notice the “Upload” link on top. It will take you to a new page where you can upload the zip file.
After uploading your plugin, you need to activate it.
- From your admin panel, go to
Extensions > Hooks
page - Clicking on cross/tick icon will activate or deactivate your plugin
It is recommended that you know the basic principles of plugin development in cakephp. Read more about it here.
A plugin is identified by it’s unique alias. If you have your plugin under the directory app/plugins/my_plugin
, then your plugin’s alias is my_plugin
.
A plugin.yml file is also required. You can see a sample file here: plugin.yml.
- app/plugins/my_plugin/
- controllers/
- components/
- my_plugin_hook.php
- my_plugin_controller.php
- components/
- models/
- views/
- my_plugin/
- helpers/
- my_plugin_hook.php
- webroot/
- plugin.yml
- css/
- img/
- js/
- my_plugin_app_controller.php
- my_plugin_app_model.php
- controllers/
Croogo supports extra callbacks for your plugins via hooks. They allow you to extend the application without having to modify the core files. A hook is either a Component or a Helper with suffix ‘Hook’.
For example, you have a plugin named MyPlugin, the hook files will be placed like this:
- MyPluginHookComponent: /app/plugins/
my_plugin
/controllers/components/my_plugin_hook.php
- MyPluginHookHelper: /app/plugins/
my_plugin
/views/helpers/my_plugin_hook.php
Any component or helper file ending with ‘_hook.php’ will be available for activating/disactivating in Extensions > Hooks
page.
Component hooks can be used when your plugin requires access to Controllers. See an example here.
-
onActivate: Called after activating the hook from
Extensions > Hooks
page. -
onDeactivate: Called after deactivating the hook from
Extensions > Hooks
page.
The following callbacks will work once the hook has been activated:
- startup: Called after the Controller::beforeFilter() and before the controller action
- beforeRender: Called after the Controller::beforeRender(), after the view class is loaded, and before the Controller::render()
- shutdown: Called after Controller::render() and before the output is printed to the browser.
Helper hooks can be used when your plugin requires to change the layout or even the content of a node before it is rendered. See an example here.
-
onActivate: Called after activating the hook from
Extensions > Hooks
page. -
onDeactivate: Called after deactivating the hook from
Extensions > Hooks
page.
The following callbacks will work once the hook has been activated:
- afterSetNode: Called after LayoutHelper::setNode(). A good place to modify node content.
- beforeNodeInfo: Called before LayoutHelper::nodeInfo().
- afterNodeInfo: Called after LayoutHelper::nodeInfo().
- beforeNodeBody: Called before LayoutHelper::nodeBody().
- afterNodeBody: Called after LayoutHelper::nodeBody().
- beforeNodeMoreInfo: Called before LayoutHelper::nodeMoreInfo().
- afterNodeMoreInfo: Called after LayoutHelper::nodeMoreInfo()
including the basic callbacks for a helper:
- beforeRender: Called before the view file is rendered.
- afterRender: Called after the view file is rendered but before the layout has been rendered.
- beforeLayout: Called before the layout is rendered.
- afterLayout: Called after the layout has rendered.
Create a zip archive of the plugin directory, in this case app/plugins/my_plugin
. It can then later be uploaded from admin panel.
You can find an example plugin in the repository. All hook/callback methods are documented: http://github.com/croogo/croogo/tree/master/plugins/example/.