Hooks in the Management Panel

2 views Markdown

The 87 points that add to a screen in the management panel. Plus the 7 hooks making a new capability known to it.

Overview

The panel takes two kinds of widening. Screen points add HTML to a page that already exists. Registration hooks make something new known to the panel: a menu entry, a dashboard box, a permission, a report.

The two serve different jobs. Putting information in a corner of a screen is a screen point. Opening a page and a permission of your own is a registration hook.

Structure

Panel templates are plain PHP and a hook point is called inside the template itself. The naming follows the same pattern as the customer site: family, screen, spot.

templates/admin/users/detail.php
<?php foreach (Hook::run('ui:admin.client_detail.bottom', $user, $user_id) as $html)
    echo $html;

Reference

Screen points

How the eighty-seven points spread across the screens. List and edit screens follow a shared pattern, so a point you find on one usually exists on its siblings too.

messages_detail (4) The contact message detail
analytics (3) The analytics screen
dashboard (3) The dashboard itself
notification_list (3) The notification template list
staff_edit (3) Editing a staff member
tickets_list (3) The ticket list
head + body (4) The page head and the end of the body — for adding CSS and JS
*_list / *_edit (30) The shared pattern of list and edit screens: before the table, the toolbar, under the form

Registration hooks

Seven registration hooks. Their contracts differ from one another. Some want a registration array returned. Some want you to add to a structure handed to you, and ignore your return. Read the entry before writing.

register:admin.menu Adds your own entry to the management menu.
register:admin.dashboard_widgets Adds your own box to the dashboard.
register:admin.privileges Adds permissions of your own to the privilege tree.
register:admin.operations Registers a new operation on the panel.
register:admin.analytics_reports Adds a report of your own to the analytics screen.
register:admin.predefined_addons Adds ready-made add-on definitions.
register:admin.captcha_protected_areas Widens the areas asking for a captcha.

Two contracts

coremio/modules/Addons/Acme/hooks.php
// A BOX: the definition array is RETURNED
Hook::add('register:admin.dashboard_widgets', 10, function () {
    return ['name' => 'Acme', 'status' => 'open', 'size' => 6];
});

// THE MENU: the return is ignored and the change goes through the global menu structure
Hook::add('register:admin.menu', 10, function () {
    $GLOBALS['menus']['acme'] = ['name' => 'Acme', 'link' => 'acme/report'];
});

Pitfalls

A menu entry opens no permission

The menu hook puts the link there and nothing else. The page itself still wants a permission, and a separate registration hook makes that permission known. Without both, an operator sees the entry and gets a refused answer on clicking it.

Panel templates are plain PHP

On the customer site a hook is called with a template tag. In the panel it is a direct PHP call and the returns are echoed by hand. So how many values a point passes changes from screen to screen. Check the parameters against the hook's entry.

Registration hooks share no contract

Some of the seven want you to return an array and some want you to add to a structure handed to you. Getting it the wrong way round is silent: you return your array, nothing appears, and no error is raised.

Panel hooks are not open to the customer

These points run on signed-in staff pages alone, so a customer never sees them. Even so, filter what you show by the staff member's permissions: not every operator should see everything.

Was this helpful?

Thanks for your feedback!

Still Need Help?

Our support team is here around the clock for anything you can't find above.