Brimbox Logo Brimbox Version 2.3.4 Released


Hooks in Brimbox allow customization. Hooks can be either global or inside a function.

In a module at global scope a hook looks like:


Inside a function a hook looks like:

$locals = get_defined_vars();
$main->hook('bb_brimbox_hookname', $locals);
foreach ($locals as $key => $value) $ {$key} = $value;

Note that this is not as inefficient as it looks, the hook will unset locals if the hook is not defined.

This way hooks in Brimbox can have any variable at the global scope or within an executing function passed in.

To set a hook add it to $array_globals:

                  array (
                        'func' => "hook_function", 
                        'vars' => array("&arr_state","title"), 
                        'locals' => array("row_type"),
                        'file' => 
                        'filter'=> "row_type", (or)
                        'global'=> "title",

Array Definition

  • 'hooks' is the variable used when parsing the global array (parsed to $array_hooks).
  • "bb_brimbox_hookname" is the hook name.
  • 'func' => "hook_function" is the callable hook function. Can be a callable class method.
  • 'vars' => array("&arr_state", "title") are the global variables passed in.
  • 'locals' => array("row_type") are the local variables passed in if the hook is in a function.
  • 'file' => "/bb-modules/bb_contains_hook_function.php" could contain the hook function if not already included.
  • Either 'filter'=> "row_type" or 'global'=> "title" can be used to define a hook return value from locals or vars respectively but not both. The matching variable must be declared with the locals or vars array items.
  • 20 is the priority used when a hook has multiple hook functions hooked. Multiple hooks can be set at one priority.


  • Note having a "&" before the vars and locals array items will pass variables by reference.
  • A variable in the locals array may have the same name as a variable in vars array. Just change the name of one of the variables in the function parameters.

Contact Us if you need a hook and filter implemented in the core.


Here is a hook example that works with the sample database producing a dropdown of Breeds in the Animals input form. Paste this inside bb_functions.php in the bb-config folder.

$main->add_action('hooks', "bb_input_field_output", 
                  array('func' => 'bb_breeds_dropdown',
                  'locals' => array('&field_output', 'input', 'key', 'value')), 

function bb_breeds_dropdown(&$field_output, $input, $key, $value) {
    global $main, $con, $arr_state;
    if (($arr_state['row_join'] == 1) && ($key == 41)) {
        $dropdowns = array(0=>"");
        $query = "SELECT id, c01 FROM data_table 
                       WHERE row_type = 3 ORDER BY c01;";
        $result = $main->query($con, $query);
        while ($row = pg_fetch_array($result)) {
            $dropdowns[] = "C" . $row['id'] . ":" . $row['c01']; 
        $field_output = "<label 
        class=\"spaced padded right pad_left 
        overflow medium pad_textbox shaded\" 
        for=\"" . $col . "\">" . 
        htmlentities($value['name']) . ": </label>";
        $field_output.= "<select id=\"" . $field_id . "\" 
        class = \"spaced\" name=\"c41\">";

        foreach ($dropdowns as $dropdown) {
            $selected = ($dropdown == $input) ? " selected" : "";
            $field_output.= "<option value=\"". $dropdown . "\"" . 
            $selected . ">" . $dropdown . "&nbsp;</option>";
        $field_output.= "</select>";
        $field_output.= "<label class=\"error\"></label>";
        $field_output.= "<div class=\"clear\"></div>";

Updated: 2017-09-10