====== Admidio Hooks Catalogue ====== This page documents every hook actually implemented in Admidio 6.0. Engine: ''Admidio\Hooks\Hooks'' (static). Three primitives — Action (''addAction''/''doAction''), Filter (''addFilter''/''applyFilters''/''applyTypedFilters''), Resolver (''addResolver''/''resolve''). See the [[..:hooks|developer documentation]] how to use the hooks documented here in your own code, and the [[..:plugin_manager|plugin manager]] for how a plugin registers them. ---- ===== 1. User Interface (GUI) customizations ===== ==== Page texts and rendering ==== ^ Hook ^ Type ^ Args ^ Dispatched from ^ | ''page_title'' | ''Filter'' | ''(string $title, PagePresenter $page)'' | ''PagePresenter::show()'' (or ''getFilteredTitle()'' for a caller that needs it earlier) | | ''page_headline'' | ''Filter'' | ''(string $headline, PagePresenter $page)'' | ''PagePresenter::show()'' (or ''getFilteredHeadline()'') | | ''page_before_render'' | Action | ''(PagePresenter $page)'' | ''PagePresenter::show()'', after the two text filters | Both filters and the action fire exactly once per page regardless of how many times ''show()'' / ''getFilteredTitle()'' / ''getFilteredHeadline()'' are called on it. ''PagePresenter::getHtmlID()'' gives the stable per-page identifier (''adm_[_]'') to key behaviour on. ==== Page frame: header bar, profile menu and notices ==== The frame of every page — the header bar with the profile menu and the area above the content — is rendered by the theme from ''index.tpl''. Plugins fill it through three filters instead of adding HTML to the page and moving it into place with JavaScript. The entries are **data, not HTML**: the theme renders and encodes them, so it can style them its own way. ^ Hook ^ Type ^ Args ^ Where ^ | ''page_header_items'' (''PageExtensions::HOOK_HEADER_ITEMS'') | ''Filter'' | ''(array $items, PagePresenter $page)'' | header bar, left of the profile photo (for visitors left of the login link) | | ''page_user_menu_items'' (''PageExtensions::HOOK_USER_MENU_ITEMS'') | ''Filter'' | ''(array $items, PagePresenter $page)'' | profile menu, between //My profile// and //Logout//; only for a logged-in user | | ''page_notices'' (''PageExtensions::HOOK_NOTICES'') | ''Filter'' | ''(array $notices, PagePresenter $page)'' | alerts at the top of the content area | All three are dispatched once per page from ''PagePresenter::show()'', right after ''page_before_render''. A page in the reduced layout (inline or print view) has no frame, so they are not dispatched for it. An **item** of the header bar is an array with these keys: ^ Key ^ ^ Meaning ^ | ''id'' | required | Stable name of lowercase letters, digits, ''-'' and ''_''; a plugin starts it with its plugin ID. It becomes the HTML id ''adm_header_item_''. | | ''label'' | required unless there is an ''icon'' or ''image'' | Text or translation ID. Next to an icon or image it is hidden on small screens and stays the accessible name of the item. | | ''tooltip'' | required without a ''label'' | Title of the item, or a translation ID; without a label it is the accessible name. | | ''icon'' | | Bootstrap icon class, e.g. ''bi-translate''. | | ''image'' | | URL of a small image shown instead of the icon, e.g. a flag; scaled to the height of the text. | | ''url'' | | The link. An item without ''url'' and without ''items'' is shown as plain text (a badge). | | ''popup'' | | Open the ''url'' in the modal dialog of the page instead of following it; the URL answers with the content of the dialog (''modal-header'', ''modal-body''), like the other popups of Admidio. | | ''popupClass'' | | Size class of that dialog, e.g. ''modal-lg''; default is the normal size. | | ''items'' | | List of entries of the same shape, without further ''items'': the item becomes a dropdown. Inside a dropdown an entry with ''header'' => true is a heading (it needs a label), one with ''divider'' => true a separator; both need no ''id''. ''active'' => true marks the current choice. | | ''class'' | | Additional CSS classes, e.g. ''text-bg-warning''. Without one, the item takes the colours of the header bar. | | ''sequence'' | | Default 100. Lower values are shown further left, or further up in a dropdown. | An entry of the **profile menu** has the same keys, without ''items''. A **notice** is an array with ''id'', ''html'' and optionally ''type'' (a Bootstrap alert type: ''primary'', ''secondary'', ''success'', ''info'' (default), ''warning'', ''danger'', ''light'', ''dark'') and ''sequence''. **''html'' of a notice is trusted HTML of the plugin.** It is output as it is, so the plugin has to encode everything it did not write itself. Labels, tooltips and URLs of items are encoded by the templates; the ''id'', ''class'' and ''icon'' are checked against their patterns. ''url'' and ''image'' must be relative or use http(s) — an ''image'' may also be a ''data:image/'' URL — so a ''javascript:'' URL is refused. A filter that fails is logged and ignored, and so is every entry that is not valid: a broken plugin can neither take the page frame down nor hide the entries of other plugins. Duplicate IDs are not detected. Hooks::addFilter('page_user_menu_items', function (array $items, PagePresenter $page): array { $items[] = array('id' => 'myplugin_switch', 'label' => 'PLG_MYPLUGIN_SWITCH', 'icon' => 'bi-arrow-left-right', 'url' => $dialogUrl, 'popup' => true); return $items; }, 10, 2, 'myplugin-user-menu'); The page frame is part of the theme: a theme with an ''index.tpl'' of its own shows these entries only if it renders the variables ''headerItems'', ''userMenuItems'' and ''pageNotices'' (the ''simple'' theme includes ''sys-template-parts/page.header-items.tpl'' for the header items). ---- ===== 2. Entity persistence lifecycle ===== Implemented once in ''Entity''. Every hookable entity dispatches the same nine stages under its own name and under the generic ''entity_*'' name. A plugin normally subscribes to the entity-specific name; a cross-cutting plugin (audit, Devhelper) subscribes to the generic one. ==== Stage pattern ==== ^ Stage ^ Type ^ Generic name ^ Entity-specific name ^ Order ^ Args ^ | pre-create | Action | ''entity_creating'' | ''_creating'' | generic first | ''(EntityChangeSet $changeSet, ?Entity $entity)'' | | post-create (committed) | Action | ''entity_created'' | ''_created'' | specific first | ''(EntityChangeSet $changeSet, ?Entity $entity)'' | | create failed | Action | ''entity_create_failed'' | ''_create_failed'' | specific first | ''(EntityChangeSet $changeSet, ?Entity $entity)'' | | pre-update | Action | ''entity_updating'' | ''_updating'' | generic first | ''(EntityChangeSet $changeSet, ?Entity $entity)'' | | post-update (committed) | Action | ''entity_updated'' | ''_updated'' | specific first | ''(EntityChangeSet $changeSet, ?Entity $entity)'' | | update failed | Action | ''entity_update_failed'' | ''_update_failed'' | specific first | ''(EntityChangeSet $changeSet, ?Entity $entity)'' | | pre-delete | Action | ''entity_deleting'' | ''_deleting'' | generic first | ''(EntityChangeSet $changeSet, ?Entity $entity)'' | | post-delete (committed) | Action | ''entity_deleted'' | ''_deleted'' | specific first | ''(EntityChangeSet $changeSet, null)'' | | delete failed | Action | ''entity_delete_failed'' | ''_delete_failed'' | specific first | ''(EntityChangeSet $changeSet, null)'' | | proposed field value | Filter | ''entity_value'' | ''_value'' | generic first | ''(mixed $value, Entity $entity, string $columnName, mixed $oldValue)'' | | readable name | Filter | ''entity_readable_name'' | ''_readable_name'' | generic first | ''(string $name, Entity $entity)'' | **The second argument is the live entity**, so a callback can read a field the change set does not carry (an unchanged column, a related record) or call a domain method on it — not just observe what changed. It is ''null'' for exactly two stages: ''deleted'' and ''delete_failed''. ''Entity::delete()'' clears the object before either can be dispatched — immediately for a failure outside a transaction, later through the commit/rollback queue for everything else — and a bulk deletion reuses one scratch object for every row it removes, so the object at that point would as often be the wrong record as an empty one. ''EntityChangeSet::getSnapshot()'' is what those two describe the record from instead. Committed (''*_created''/''*_updated''/''*_deleted'') fires after the outermost transaction really commits, never before, and never for a change that is later rolled back. Two saves of the same record in one transaction coalesce into one event. A create+delete of the same never-persisted record fires nothing. ''*_value'' runs before Admidio's own type canonicalization, so it sees the proposed input, not the stored form. Bulk-deleted dependent records (''Entity::deleteDependentRecords()'' / ''hookBulkDeletion()'') dispatch the same ''deleting''/''deleted'' pair per record, with ''EntityChangeSet::isCascade()'' / ''getCauseHookId()'' / ''getCauseId()'' naming the record whose deletion caused it. A membership whose start or end date is simply //reached// is not saved, so it dispatches none of these stages; see ''membership_period_changed'' in section 3. ==== Entities and their hook ID ==== ^ Hook ID () ^ Class ^ Table ^ | ''announcement'' | ''Announcements\Entity\Announcement'' | ''adm_announcements'' | | ''category'' | ''Categories\Entity\Category'' | ''adm_categories'' | | ''category_report'' | ''CategoryReport\Entity\CategoryReport'' | ''adm_category_report'' | | ''category_report_column'' | ''CategoryReport\Entity\CategoryReportColumn'' | ''adm_category_report_columns'' | | ''component'' | ''Components\Entity\Component'' | ''adm_components'' | | ''event'' | ''Events\Entity\Event'' | ''adm_events'' | | ''file'' | ''Documents\Entity\File'' | ''adm_files'' | | ''folder'' | ''Documents\Entity\Folder'' | ''adm_folders'' | | ''forum_post'' | ''Forum\Entity\Post'' | ''adm_forum_posts'' | | ''forum_topic'' | ''Forum\Entity\Topic'' | ''adm_forum_topics'' | | ''inventory_field'' | ''Inventory\Entity\ItemField'' | ''adm_inventory_fields'' | | ''inventory_field_select_option'' | ''Inventory\Entity\SelectOptions'' | ''adm_inventory_field_options'' | | ''inventory_item'' | ''Inventory\Entity\Item'' | ''adm_inventory_items'' | | ''inventory_item_borrow_data'' | ''Inventory\Entity\ItemBorrowData'' | ''adm_inventory_item_borrow_data'' | | ''inventory_item_data'' | ''Inventory\Entity\ItemData'' | ''adm_inventory_item_data'' | | ''inventory_reservations'' | ''Inventory\Entity\Reservation'' | ''adm_inventory_reservations'' | | ''list_column'' | ''Roles\Entity\ListColumns'' | ''adm_list_columns'' | | ''list_configuration'' | ''Roles\Entity\ListConfiguration'' | ''adm_lists'' | | ''membership'' | ''Roles\Entity\Membership'' | ''adm_members'' | | ''menu_entry'' | ''Menu\Entity\MenuEntry'' | ''adm_menu'' | | ''message'' | ''Messages\Entity\Message'' | ''adm_messages'' | | ''message_content'' | ''Messages\Entity\MessageContent'' | ''adm_messages_content'' | | ''oidc_client'' | ''SSO\Entity\OIDCClient'' | ''adm_oidc_clients'' | | ''organization'' | ''Organizations\Entity\Organization'' | ''adm_organizations'' | | ''photo_album'' | ''Photos\Entity\Album'' | ''adm_photos'' | | ''profile_field'' | ''ProfileFields\Entity\ProfileField'' | ''adm_user_fields'' | | ''profile_field_select_option'' | ''ProfileFields\Entity\SelectOptions'' | ''adm_user_field_options'' | | ''role'' | ''Roles\Entity\Role'' | ''adm_roles'' | | ''role_dependency'' | ''Roles\Entity\RolesDependencies'' | ''adm_role_dependencies'' | | ''role_right'' | ''Roles\Entity\RolesRights'' | ''adm_roles_rights'' | | ''role_right_assignment'' | ''Roles\Entity\RolesRightsData'' | ''adm_roles_rights_data'' | | ''room'' | ''Events\Entity\Room'' | ''adm_rooms'' | | ''saml_client'' | ''SSO\Entity\SAMLClient'' | ''adm_saml_clients'' | | ''sso_key'' | ''SSO\Entity\Key'' | ''adm_sso_keys'' | | ''user'' | ''Users\Entity\User'' | ''adm_users'' | | ''user_data'' | ''Users\Entity\UserData'' | ''adm_user_data'' | | ''user_relation'' | ''Users\Entity\UserRelation'' | ''adm_user_relations'' | | ''user_relation_type'' | ''Users\Entity\UserRelationType'' | ''adm_user_relation_types'' | | ''weblink'' | ''Weblinks\Entity\Weblink'' | ''adm_links'' | ==== Deliberately unhookable (no hook ID, dispatch nothing) ==== ''LogChanges'', ''Text'', ''Preferences'', ''AutoLogin'', ''Session'', ''SSOClient'' (its subclasses ''OIDCClient''/ ''SAMLClient'' are hookable), ''TokenEntity'' (OIDC access/refresh tokens, auth codes). Infrastructure, security-sensitive, or too high-frequency to be normal CRUD subjects. ---- ===== 3. Semantic / cross-cutting hooks ===== ^ Hook ^ Type ^ Args ^ Dispatched from ^ | ''user_registration_accepted'' | Action | ''(User $user, string $method)'' — ''$method'' is ''UserRegistration::ACCEPTED_BY_APPROVAL'' or ''::ACCEPTED_BY_ASSIGNMENT'' | ''UserRegistration::acceptRegistration()'', ''RegistrationService::assignRegistration()'' | | ''user_changes_cumulated'' | Action | ''(string $userUuid, array $reasons)'' — reasons are a subset of ''user'', ''profile'', ''membership'' | ''ChangeNotification::sendNotifications()'', once per affected user per request | | ''membership_period_changed'' | Action | ''(array $membership, string $change)'' — ''$membership'' has ''mem_id'', ''mem_uuid'', ''mem_usr_id'', ''mem_rol_id'', ''mem_begin'', ''mem_end'', ''mem_leader''; ''$change'' is ''started'' or ''ended'' (''MembershipPeriodService::CHANGE_STARTED'' / ''::CHANGE_ENDED'') | ''MembershipPeriodService'', once per day: the maintenance job ''memberships'', or the first request of the day for installations without cron | ''membership_period_changed'' reports the memberships whose start or end date was reached without anybody saving them, which the entity hooks of ''membership'' cannot see. A day is processed under a lock and recorded only when it is done; a run that fails is repeated. A callback that fails is logged and does not stop the others (''doActionCatchErrors()''), and the day is not repeated because of it — the change has already happened and nothing could undo it. Doing a day twice is possible after a failed run, so a callback should tolerate seeing the same change again. ---- ===== 4. Forms ===== ^ Hook ^ Type ^ Args ^ Dispatched from ^ | ''form_built'' | Action | ''(FormPresenter $form)'' | ''FormPresenter::finalize()'' — once per form, however many times/from where ''finalize()'' is reached | | ''form_select_options'' | Filter | ''(array $values, string $elementId, string $elementType, FormPresenter $form)'' — must return an array of the same shape | ''FormPresenter::finalize()'', after ''form_built'', only for ''select'' / ''radio'' / ''button-group.radio'' elements | ''form_select_options'''s result is enforced: it is the same element definition ''validate()'' checks a POST against, so removing an entry there really refuses it server-side. ---- ===== 5. Components and menu ===== ^ Hook ^ Type ^ Args ^ Dispatched from ^ | ''component_visible'' | ''Filter'' | ''(bool $visible, string $componentName)'' | ''Component::isVisible()'' | | ''component_administrable'' | ''Filter'' | ''(bool $administrable, string $componentName)'' | ''Component::isAdministrable()'' | | ''menu_item_visible'' | ''Filter'' | ''(bool $visible, int $menuId, string $componentName)'' — ''$componentName'' is the internal name of the component owning the entry, or empty | ''MenuNode::menuItemIsVisible()'', after the role rights of the menu entry decided ''$visible'' | Typed filters — a callback must return a ''bool'', not a truthy value. Hiding a menu entry only removes the entry; the page behind it still checks the permissions of the user. ---- ===== 6. Translation ===== ^ Hook ^ Type ^ Args ^ Dispatched from ^ | ''translation_text'' | ''Filter'' | ''(string $text, string $textId, string $language)'' | ''Language::get()'', on every lookup, after the cache read | | ''translation_missing'' | Resolver | ''(string $textId, string $language)'', default ''null'' | ''Language::get()'', only when neither the requested nor the reference language has the text | | ''translation_fallback_used'' | Action | ''(string $textId, string $language, string $referenceLanguage)'' | ''Language::get()'', when the reference-language text was used | | ''translation_unresolved'' | Action | ''(string $textId, string $language)'' | ''Language::get()'', when nothing — requested, reference, or resolver — produced a text | ---- ===== 7. Login, session, logout and request ===== ^ Hook ^ Type ^ Args ^ Dispatched from ^ | ''login_attempt'' | Action | ''(string $loginName, string $orgShortName)'' | ''LoginService'', at the start of a login attempt; throwing refuses it | | ''login_succeeded'' | Action | ''(User $user, string $orgShortName)'' | ''LoginService'', after a successful login | | ''login_failed'' | Action | ''(string $loginName, string $reason, string $orgShortName)'' — no password/TOTP | ''LoginService'', for an unknown user as well as a wrong password/TOTP | | ''auto_login_succeeded'' | Action | ''(Session $session)'' | ''Session'', when a user is authenticated by an auto-login token — the counterpart of ''login_succeeded'' for that case, dispatched once per session | | ''session_id'' | Resolver | ''(string $sessionName)'', default ''null'' — answers a session ID | ''Session::start()'', only when the request carries no session cookie and no session is active yet | | ''logout_target'' | Resolver | ''(User $user)'', default ''null'' — answers a URL | ''system/logout.php'', before anything else: a non-empty answer redirects there //instead of// logging out | | ''logout'' | Action | ''(User $user)'' | ''system/logout.php'', and the single logout of SAML and OIDC (''SAMLService'', ''OIDCService''); the user is still known at that point | | ''logout_homepage'' | ''Filter'' | ''(string $url)'' | ''system/logout.php'', after the logout: where the visitor is sent afterwards | | ''logout_response'' | Resolver | ''(string $homepage)'', default ''null'' — answers a PSR-7 ''ResponseInterface'' | ''system/logout.php'', after ''logout_homepage'': a response finishes the logout instead of the logout message | | ''exception_terminating'' | Action | ''(Throwable $exception, bool $isJsonResponse)'' | ''handleException()'' | | ''request_finished'' | Action | ''()'' | ''admShutdown()'', at the end of every request (web and CLI) | ''session_id'' lets a request continue a session it does not carry the cookie of, e.g. a cross-site form post that does not send the ''SameSite=Lax'' cookie. An answer that does not look like a session ID (''[A-Za-z0-9,-]'', 22–256 characters) is ignored. ''logout_target'' is for a plugin that takes the logout over, e.g. one that lets an administrator act as another user and returns to the administrator: the session, and the single sign-on clients of the session, stay logged in. ''logout_response'' is how the single sign-on module ends a logout with the logout chain of the clients of the session; that chain ends at the address ''logout_homepage'' produced. ''request_finished'' is for work that does not have to delay the answer. Where PHP-FPM allows it, the response is sent first (''fastcgi_finish_request()''), the session is closed before the listeners run, and anything a listener writes into the session is lost. Without PHP-FPM the listeners run synchronously and delay the response. A request that left a transaction open does not dispatch it, because everything a listener wrote would be rolled back with that transaction. A failing listener is logged and does not stop the others. The single sign-on module registers its own core listeners through these hooks (''SSOHooks'' with the registration ID ''sso'', ''SSOSessionCookie'' with ''sso_session_cookie''): ''logout'', ''logout_response'', ''login_succeeded'', ''auto_login_succeeded'', ''session_id'' and the ''membership'' entity hooks. A plugin must not reuse those registration IDs on these hooks, because registering an ID again replaces it. ---- ===== 8. Email ===== ^ Hook ^ Type ^ Args ^ Dispatched from ^ | ''email_recipients'' | ''Filter'' | ''(array $recipients, string $subject)'' | ''Email::sendEmail()'' (internally ''deliver()''), before sending | | ''email_sent'' | Action | ''(string $subject, int $recipientCount)'' | ''Email'', after a successful send | | ''email_failed'' | Action | ''(string $subject, int $recipientCount, string $errorMessage)'' | ''Email'', after a failed send | No email hook ever receives the ''Email''/PHPMailer object — it carries the SMTP credentials in public properties. ---- ===== 9. Lists ===== ^ Hook ^ Type ^ Args ^ Dispatched from ^ | ''list_row_actions'' | ''Filter'' | ''(array $actions, string $listId, array $row)'' — a list of action items | ''ListActions::filter()'', for every list that renders action icons (template ''sys-template-parts/list.functions.tpl'' or the Smarty function ''{list_actions}'') | | ''list_columns'' | ''Filter'' | ''(array $columnHeadings, string $listId)'' — must return the same number of entries | ''contacts.php'', before the headings are handed to the page | | ''list_data'' | ''Filter'' | ''(array $row, string $listId)'' | ''contacts_data.php'', right after a row is fetched, before formatting | | ''list_rendered_data'' | ''Filter'' | ''(array $columnValues, string $listId, array $row)'' | ''contacts_data.php'', right before a row is added to the JSON response | ==== list_row_actions ==== A plugin can add, hide, change and reorder the action icons (edit, delete, history, …) of a row. An action item is an array with * **icon** (required) — CSS classes of the icon, e.g. ''bi bi-pencil-square'', * **tooltip** (required) — the translated tooltip, which is also the accessible label; empty only for the invisible placeholder with the ID ''spacer'', * **id** (optional) — a stable name such as ''edit'' or ''delete''; a plugin starts the IDs of its own actions with its plugin ID, * **url**, **popup**, **dataMessage** + **dataHref**, **class**, **attributes** (optional) — what a click does; an item without any of them only shows its icon and tooltip. The first item stays visible when a row has more than two actions; the others move into the menu of the row, so reordering also decides which one is shown directly. Hiding an action only removes its icon: the page behind it still checks the permissions of the user. ''$row'' is the database row for ''contacts'' and the array the template renders for every other list. A filter that fails or returns something that is not a list of action items (each with ''icon'' and ''tooltip'') is logged, and the row is rendered with its unfiltered actions. Hooks::addFilter('list_row_actions', function (array $actions, string $listId, array $row): array { if ($listId === 'menu') { // hide the delete icon of the menu entries return array_values(array_filter($actions, fn($action) => ($action['id'] ?? '') !== 'delete')); } if ($listId === 'contacts') { // add an own action to the contacts $actions[] = array('id' => 'myplugin_print', 'url' => '/print.php?user=' . $row['usr_uuid'], 'icon' => 'bi bi-printer', 'tooltip' => 'Print'); } return $actions; }, 10, 3, 'myplugin-actions'); The list IDs: ''announcements'', ''categories'', ''category-report'', ''contacts'', ''documents-files'', ''events'', ''forum-posts'', ''forum-topics'', ''inventory-borrow'', ''inventory-fields'', ''inventory-items'', ''inventory-reservations'', ''menu'', ''photo-albums'', ''photos'', ''plugin-store'', ''plugins'', ''profile-fields'', ''profile-inventory'', ''profile-relations'', ''profile-roles'', ''role-permissions'', ''roles'', ''sso-clients-oidc'', ''sso-clients-saml'', ''sso-keys'', ''weblinks''. ==== Column and data hooks ==== ''list_columns'', ''list_data'' and ''list_rendered_data'' are implemented for one list so far, ''contacts''. ''list_columns'' can relabel a column but not add or remove one: rows are still built by column position, there is no shared list/column pipeline yet, and a count change is refused with an exception rather than silently misaligning every row. ---- ===== 10. Plugins ===== ^ Hook ^ Type ^ Args ^ Dispatched from ^ | ''plugins_loaded'' | Action | ''(array $plugins)'' — pluginId => ''Plugin'' of every plugin loaded in this request | ''PluginLoader::loadEnabled()'', after all enabled plugins were loaded | | ''overview_widgets'' (''PluginWidget::HOOK'') | ''Filter'' | ''(array $widgets, PagePresenter $page)'' — widget entries | ''PluginWidget::collect()'', on the overview page | | ''preferences_panels'' (''PluginPanel::HOOK'') | ''Filter'' | ''(array $panels)'' — panel declarations | ''PluginPanel::collect()'', once per request, when the preferences page or the settings dialog of the plugin manager asks for the panels | | ''plugin_removal_warnings'' | ''Filter'' | ''(array $warnings, Plugin $plugin)'' — plain-text messages | ''PluginInstaller::getRemovalWarnings()'', for the confirmation before a plugin is removed (web and ''plugin:remove'') | ''plugins_loaded'' is the place for work that needs other plugins to be present, because the order in which plugins are loaded is not defined. A **widget entry** is an array with ''id'' and ''html'' (required), ''name'' (the heading) and ''sequence'' (position, default 100). Entries without ''id'' or ''html'' are skipped; widgets of the same sequence are ordered by their ID. A plugin that follows the conventions (one widget, ''_overview_sequence'' and ''_plugin_enabled'' preferences) calls ''PluginWidget::register()'' instead of adding the filter itself; the declaration is what the overview preferences list, so a widget that is switched off can be switched on again. A **panel declaration** is an array with ''id'' and ''create'' (required; a callable that receives the ''PreferencesPresenter'' and returns the HTML of the panel), and optionally ''title'', ''icon'', ''section'', ''sequence'' and ''subcards''. Section and sequence default to the ''preferences'' of the manifest of the plugin the panel is named after. ''create'' is only called for the panel that is actually opened. A plugin whose settings form is generated from its manifest needs no panel declaration at all. ''plugin_removal_warnings'' tells the administrator what removing the plugin leaves behind (e.g. accounts on a remote system that are no longer managed). A warning never prevents the removal — otherwise a broken plugin could not be removed. For the same reason a callback that fails or returns something other than a list is logged, and there are no warnings then. Only a loaded plugin can answer, i.e. one that is enabled in the current organization. Hooks::addFilter('plugin_removal_warnings', function (array $warnings, Plugin $plugin): array { if ($plugin->id === 'example' && ExampleService::hasRemoteData()) { $warnings[] = 'The accounts on the remote system are no longer managed.'; } return $warnings; }, 10, 2, 'example-removal'); ---- ===== 11. Module-specific (not part of the generic vocabulary) ===== ^ Hook ^ Type ^ Args ^ Dispatched from ^ | ''category_report_enabled'' | ''Filter'' | ''(bool $enabled)'' | ''category_report.php'' | | ''category_report_config'' | ''Filter'' | ''(array $config)'' | ''CategoryReportPresenter'' | Kept deliberately module-specific: ''category_report_config'' is genuine module data with no generic equivalent, and ''category_report_enabled'' lets the module tell a direct URL "disabled" apart from "no rights" after ''component_visible'' already folds the setting into ''Component::isVisible()''. ---- ===== Hook engine API reference ===== Hooks::DEFAULT_PRIORITY // 10 Hooks::addAction(string $name, callable $callback, int $priority = 10, ?int $acceptedArgs = null, ?string $id = null): void Hooks::doAction(string $name, mixed ...$args): void Hooks::doActionCatchErrors(string $name, mixed ...$args): void // failure/diagnostic and after-the-fact dispatch only Hooks::addFilter(string $name, callable $callback, int $priority = 10, ?int $acceptedArgs = null, ?string $id = null): void Hooks::applyFilters(string $name, mixed $value, mixed ...$args): mixed Hooks::applyTypedFilters(string $name, mixed $value, mixed ...$args): mixed // return type must match $value's Hooks::addResolver(string $name, callable $callback, int $priority = 10, ?int $acceptedArgs = null, ?string $id = null): void Hooks::resolve(string $name, mixed $default = null, mixed ...$args): mixed // first non-null answer wins Hooks::removeAction(string $name, string|callable $idOrCallback): bool Hooks::removeFilter(string $name, string|callable $idOrCallback): bool Hooks::removeResolver(string $name, string|callable $idOrCallback): bool Hooks::hasAction/hasFilter/hasResolver(string $name): bool Hooks::reset(string $name = ''): void // one hook, or the whole registry Lower priority runs earlier; same priority runs in registration order. An explicit ''$id'' is unique within one hook regardless of the priority: registering the same ID again replaces the earlier registration, and ''remove*()'' accepts the ID as well as the callback. A callback throws to veto an Action or a Filter; the exception is logged with the hook and the callback and then propagates. ''doActionCatchErrors()'' logs and swallows instead. It is used only at failure/diagnostic sites, where the original failure must stay the one Admidio reports, and for notifications about a change that already happened and that nothing could undo (''membership_period_changed'', ''request_finished''). ''applyTypedFilters()'' throws an ''UnexpectedValueException'' that names the hook and the callback when a callback returns another type than the value it received. Several dispatch sites catch that and fall back instead of failing: ''list_row_actions'' (unfiltered actions) and ''plugin_removal_warnings'' (no warnings). ''doAction()''/''doActionCatchErrors()''/''applyFilters()''/''applyTypedFilters()''/''resolve()'' are not only for core's own dispatch sites: a module or plugin can call them at its own extension points to make itself extensible by other plugins the same way core is — register the names with ''add*()'' as usual, then dispatch them from your own code with these. ---- ===== Changelog extensions ===== The change history is not extended through ''Hooks'' but through a registry of its own, ''ChangelogService::registerCallback()''. It records only changes made through an ''Entity'' (''save()'' / ''delete()''), so an extension gets its changes logged by using entities; what it registers here makes those entries readable, linkable, configurable and visible to the right users. Register the callbacks in the entry file of the plugin: they have to be in place before a changelog page is shown and before the extension writes data. ChangelogService::registerCallback(string $function, string $moduleOrKey, mixed $callback): void ''$callback'' is a value or a callable. A value is returned as it is. A callable is called with the arguments of the ''ChangelogService'' method it customizes; a non-empty answer is used, an empty one (''null'', an empty string or array) lets the next callback or the default processing decide. With ''$moduleOrKey'' set, the callback applies to that table (or value type); with an empty key, it is asked for every table. An unknown ''$function'' throws an ''InvalidArgumentException'' right at registration. ^ Function ^ Key ^ Callback / value ^ Purpose ^ | ''getTableLabelArray'' | table | translation ID | Title of a table | | ''getTableLabel'' | table or empty | ''fn(mixed $table)'' | Title of a table, computed | | ''getFieldTranslations'' | empty | array column => translation ID, or => ''array('name' => …, 'type' => …)'' | Title and type of each column | | ''formatValue'' | type | ''fn($value, $type, $entries = [])'' → HTML | Display of a value of a column type of your own (e.g. a link to the referenced record) | | ''createLink'' | table | ''%%fn(string $text, string $module, int|string $id, string $uuid = '')%%'' → URL | Link from an entry to the record | | ''getObjectForTable'' | table | ''fn()'' → ''Entity'' | Object the page headline is built from | | ''getRelatedTable'' | table | table name, or ''fn(string $table, string &$relatedName)'' | Table that the entries of this table point at | | ''getAreaArray'' | empty | array area ID => ''array('label', 'section', 'enabledBy', 'tables')'' | Area of the change-history preferences that switches logging on and off | | ''getPermittedTables'' | empty | ''fn(User $user)'' → table names | Tables whose **every** entry the user may read | | ''getOwnChangeTables'' | empty | table names, or ''fn(User $user)'' → table names | Tables in which the user may read the entries of **the changes he/she made** | ''getTableLabelArray'', ''getFieldTranslations'' and ''getAreaArray'' with an empty key are merged into the lookup tables and must be arrays. **Areas.** Logging is switched on and off per area in the preferences, never per table. An area bundles the tables of one module (''section'' is one of ''user_role_data'', ''content_modules'', ''settings'', ''other''; ''enabledBy'' names the preferences that enable the module — the area is shown as soon as one of them is on, an empty array shows it always). A registered table that no area claims lands in the area //other//, so it is configurable even without an area of its own. **Permissions.** ''getPermittedTables'' is all or nothing: a user reads either every entry of a table or none. For tables whose data members enter themselves (activities, providers, …), ''getOwnChangeTables'' opens a table to every user for the entries **they authored** (''log_usr_id_create''): the web changelog, ''changelog:list'' and ''changelog:show'' restrict those tables to the user's own entries in SQL, so counts, paging, search and grouped changes stay exact, and the changelog, its menu entry and the history buttons become available. Entries are matched by their author, not by the owner of the record — a change an administrator made to a member's record is not shown to the member — and the record is shown with the name it had at the user's own last change, not with its current name. Administrators, and users that ''getPermittedTables'' grants the table to, are never restricted. use Admidio\Changelog\Service\ChangelogService; // titles of the tables and their columns ChangelogService::registerCallback('getTableLabelArray', 'myplugin_activities', 'PLG_MYPLUGIN_ACTIVITIES'); ChangelogService::registerCallback('getFieldTranslations', '', array( 'mpa_title' => 'SYS_TITLE', 'mpa_cat_id' => array('name' => 'SYS_CATEGORY', 'type' => 'CATEGORY') )); // link from an entry to the record, and the object for the headline ChangelogService::registerCallback('createLink', 'myplugin_activities', fn(string $text, string $module, int|string $id, string $uuid = '') => SecurityUtils::encodeUrl($plugin->getUrl('activity.php'), array('uuid' => $uuid))); ChangelogService::registerCallback('getObjectForTable', 'myplugin_activities', function () { global $gDb; return new Activity($gDb); }); // an area of the change-history preferences ChangelogService::registerCallback('getAreaArray', '', array( 'myplugin' => array('label' => 'PLG_MYPLUGIN_NAME', 'section' => 'content_modules', 'enabledBy' => array('myplugin_plugin_enabled'), 'tables' => array('myplugin_activities')) )); // who may read what: managers everything, every member the changes they made themselves ChangelogService::registerCallback('getPermittedTables', '', fn(User $user) => MyPluginService::isManager($user) ? array('myplugin_activities') : array()); ChangelogService::registerCallback('getOwnChangeTables', '', array('myplugin_activities')); A page offers its history button with ''ChangelogService::displayHistoryButton($page, $area, $tables)'', a list row with ''ChangelogService::displayHistoryButtonTable($tables)'', which returns an action item for ''list_row_actions'' (empty if the user may not read the tables or logging is off).