Creating Hooks
BigTree 4.4 looks for hooks inside of each extension directory and caches them when installing a new extension or updating an existing extension. If your hook is not running, the first thing you should try is re-saving your extension or deleting /cache/bigtree-hooks.json
!
In each extension directory, you can create a /hooks/
folder with the following structure:
/hooks/
— root directory/hooks/fields/
— Field hooks directory/hooks/fields/callout.php
— Callout field hooks PHP code/hooks/fields/form.php
— Module form field hooks PHP code/hooks/fields/template.php
— Template field hooks PHP code/hooks/markup/
— Markup hooks directory/hooks/markup/dashboard-bottom.php
— PHP code / HTML markup to insert at the bottom of the Dashboard landing/hooks/markup/dashboard-top.php
— PHP code / HTML markup to insert at the top of the Dashboard landing/hooks/markup/developer-bottom.php
— PHP code / HTML markup to insert at the bottom of the Developer landing/hooks/markup/developer-buttons-configure.php
— PHP code / HTML markup to insert at the end of the "Configure" block of buttons on the Developer landing/hooks/markup/developer-buttons-create.php
— PHP code / HTML markup to insert at the end of the "Create" block of buttons on the Developer landing/hooks/markup/developer-buttons-debug.php
— PHP code / HTML markup to insert at the end of the "Debug" block of buttons on the Developer landing/hooks/markup/developer-top.php
— PHP code / HTML markup to insert at the top of the Developer landing/hooks/markup/modules-bottom.php
— PHP code / HTML markup to insert at the bottom of the Modules landing/hooks/markup/modules-top.php
— PHP code / HTML markup to insert at the top of the Modules landing/hooks/menu.php
— PHP code to modify the BigTree navigation menu (see /core/admin/_nav-tree.php
for the format of the menu).
Drawing Markup
For hooks that draw markup (in /hooks/markup/
) all that needs to be done is to output that markup in the hooks PHP file. Any PHP is acceptable in this context -- it is run as a simple include but is inside an anonymous function scope -- any global variables such as $cms
or $admin
will need to be globalized to be used.
Field and Menu Hooks
Field and menu hooks are also run within function scope but have a single variable available to them: $data
— this variable should be modified by your PHP code. It does not need to be returned, only modified. In the context of the Menu hook, $data
contains $bigtree["nav_menu"]
for modification. In the context of Field hooks, $data
contains the full set of fields to be modified — ideally either through array_push or array_unshift to append or prepend fields. These fields are processed the same as any other field — if they are not stored in the database, ensure that you are using a field type that passes $field["ignore"]
(especially for module forms as a missing column will fail to insert a record).
Example Extension
An example extension showing each of the hooks in use is available on GitHub: