| Both sides previous revision Previous revision | |
| en:entwickler:hooks:catalogue [2026/08/26 21:04] – kainhofer | en:entwickler:hooks:catalogue [2026/11/26 22:33] (current) – kainhofer |
|---|
| ====== Admidio Hooks Catalogue ====== | ====== Admidio Hooks Catalogue ====== |
| |
| This page documents every hook actually implemented in Admidio 5.1. | This page documents every hook actually implemented in Admidio 6.0. |
| |
| Engine: ''Admidio\Hooks\Hooks'' (static). Three primitives — Action (''addAction''/''doAction''), Filter | Engine: ''Admidio\Hooks\Hooks'' (static). Three primitives — Action (''addAction''/''doAction''), Filter |
| (''addFilter''/''applyFilters''/''applyTypedFilters''), Resolver (''addResolver''/''resolve''). | (''addFilter''/''applyFilters''/''applyTypedFilters''), Resolver (''addResolver''/''resolve''). |
| |
| See the [[..:hooks|developer documentation]] how to use the hooks documented here in your own code. | 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. Entity persistence lifecycle ===== | ===== 1. User Interface (GUI) customizations ===== |
| | |
| | ==== Page texts and rendering ==== |
| | |
| | ^ Hook ^ Type ^ Args ^ Dispatched from ^ |
| | | ''page_title'' | ''Filter<string>'' | ''(string $title, PagePresenter $page)'' | ''PagePresenter::show()'' (or ''getFilteredTitle()'' for a caller that needs it earlier) | |
| | | ''page_headline'' | ''Filter<string>'' | ''(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_<module>[_<view>]'') 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>'' | ''(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>'' | ''(array $items, PagePresenter $page)'' | profile menu, between //My profile// and //Logout//; only for a logged-in user | |
| | | ''page_notices'' (''PageExtensions::HOOK_NOTICES'') | ''Filter<array>'' | ''(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_<id>''. | |
| | | ''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. |
| | |
| | <code php> |
| | 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'); |
| | </code> |
| | |
| | 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 | Implemented once in ''Entity''. Every hookable entity dispatches the same nine stages under its own name |
| ''EntityChangeSet::isCascade()'' / ''getCauseHookId()'' / ''getCauseId()'' naming the record whose deletion | ''EntityChangeSet::isCascade()'' / ''getCauseHookId()'' / ''getCauseId()'' naming the record whose deletion |
| caused it. | 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 ==== | ==== Entities and their hook ID ==== |
| | ''announcement'' | ''Announcements\Entity\Announcement'' | ''adm_announcements'' | | | ''announcement'' | ''Announcements\Entity\Announcement'' | ''adm_announcements'' | |
| | ''category'' | ''Categories\Entity\Category'' | ''adm_categories'' | | | ''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'' | | | ''component'' | ''Components\Entity\Component'' | ''adm_components'' | |
| | ''event'' | ''Events\Entity\Event'' | ''adm_events'' | | | ''event'' | ''Events\Entity\Event'' | ''adm_events'' | |
| | ''inventory_item_borrow_data'' | ''Inventory\Entity\ItemBorrowData'' | ''adm_inventory_item_borrow_data'' | | | ''inventory_item_borrow_data'' | ''Inventory\Entity\ItemBorrowData'' | ''adm_inventory_item_borrow_data'' | |
| | ''inventory_item_data'' | ''Inventory\Entity\ItemData'' | ''adm_inventory_item_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_column'' | ''Roles\Entity\ListColumns'' | ''adm_list_columns'' | |
| | ''list_configuration'' | ''Roles\Entity\ListConfiguration'' | ''adm_lists'' | | | ''list_configuration'' | ''Roles\Entity\ListConfiguration'' | ''adm_lists'' | |
| ---- | ---- |
| |
| ===== 2. Semantic / cross-cutting hooks ===== | ===== 3. Semantic / cross-cutting hooks ===== |
| |
| ^ Hook ^ Type ^ Args ^ Dispatched from ^ | ^ 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_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 | | | ''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. |
| |
| ---- | ---- |
| |
| ===== 3. Forms ===== | ===== 4. Forms ===== |
| |
| ^ Hook ^ Type ^ Args ^ Dispatched from ^ | ^ Hook ^ Type ^ Args ^ Dispatched from ^ |
| ---- | ---- |
| |
| ===== 4. Pages ===== | ===== 5. Components and menu ===== |
| | |
| ^ Hook ^ Type ^ Args ^ Dispatched from ^ | |
| | ''page_title'' | ''Filter<string>'' | ''(string $title, PagePresenter $page)'' | ''PagePresenter::show()'' (or ''getFilteredTitle()'' for a caller that needs it earlier) | | |
| | ''page_headline'' | ''Filter<string>'' | ''(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_<module>[_<view>]'') to key behaviour on. | |
| | |
| ---- | |
| | |
| ===== 5. Components ===== | |
| |
| ^ Hook ^ Type ^ Args ^ Dispatched from ^ | ^ Hook ^ Type ^ Args ^ Dispatched from ^ |
| | ''component_visible'' | ''Filter<bool>'' | ''(bool $visible, string $componentName)'' | ''Component::isVisible()'' | | | ''component_visible'' | ''Filter<bool>'' | ''(bool $visible, string $componentName)'' | ''Component::isVisible()'' | |
| | ''component_administrable'' | ''Filter<bool>'' | ''(bool $administrable, string $componentName)'' | ''Component::isAdministrable()'' | | | ''component_administrable'' | ''Filter<bool>'' | ''(bool $administrable, string $componentName)'' | ''Component::isAdministrable()'' | |
| | | ''menu_item_visible'' | ''Filter<bool>'' | ''(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. | 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. |
| |
| ---- | ---- |
| ---- | ---- |
| |
| ===== 7. Login, session and diagnostics ===== | ===== 7. Login, session, logout and request ===== |
| |
| ^ Hook ^ Type ^ Args ^ Dispatched from ^ | ^ Hook ^ Type ^ Args ^ Dispatched from ^ |
| | ''login_attempt'' | Action | ''(string $loginName, string $orgShortName)'' | ''ModuleLogin'', at the start of a login attempt; throwing refuses it | | | ''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)'' | ''ModuleLogin'', after a successful login | | | ''login_succeeded'' | Action | ''(User $user, string $orgShortName)'' | ''LoginService'', after a successful login | |
| | ''login_failed'' | Action | ''(string $loginName, string $reason, string $orgShortName)'' — no password/TOTP | ''ModuleLogin'', for an unknown user as well as a wrong password/TOTP | | | ''login_failed'' | Action | ''(string $loginName, string $reason, string $orgShortName)'' — no password/TOTP | ''LoginService'', for an unknown user as well as a wrong password/TOTP | |
| | ''logout'' | Action | ''(User $user)'' | ''system/logout.php'' | | | ''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>'' | ''(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()'' | | | ''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. |
| |
| ---- | ---- |
| |
| ===== 9. Lists ===== | ===== 9. Lists ===== |
| |
| Proven on one module (''contacts'') with the stable ''listId'' ''contacts''; not yet implemented for any | |
| other list. | |
| |
| ^ Hook ^ Type ^ Args ^ Dispatched from ^ | ^ Hook ^ Type ^ Args ^ Dispatched from ^ |
| | | ''list_row_actions'' | ''Filter<array>'' | ''(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>'' | ''(array $columnHeadings, string $listId)'' — must return the same number of entries | ''contacts.php'', before the headings are handed to the page | | | ''list_columns'' | ''Filter<array>'' | ''(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>'' | ''(array $row, string $listId)'' | ''contacts_data.php'', right after a row is fetched, before formatting | | | ''list_data'' | ''Filter<array>'' | ''(array $row, string $listId)'' | ''contacts_data.php'', right after a row is fetched, before formatting | |
| | ''list_row_actions'' | ''Filter<string>'' | ''(string $actionsHtml, string $listId, array $row)'' | ''contacts_data.php'', right before the action-icons cell is written | | |
| | ''list_rendered_data'' | ''Filter<array>'' | ''(array $columnValues, string $listId, array $row)'' | ''contacts_data.php'', right before a row is added to the JSON response | | | ''list_rendered_data'' | ''Filter<array>'' | ''(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. |
| | |
| | <code php> |
| | 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'); |
| | </code> |
| | |
| | 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, | ''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 | there is no shared list/column pipeline yet, and a count change is refused with an exception rather than |
| ---- | ---- |
| |
| ===== 10. Module-specific (not part of the generic vocabulary) ===== | ===== 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>'' | ''(array $widgets, PagePresenter $page)'' — widget entries | ''PluginWidget::collect()'', on the overview page | |
| | | ''preferences_panels'' (''PluginPanel::HOOK'') | ''Filter<array>'' | ''(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>'' | ''(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, ''<id>_overview_sequence'' and |
| | ''<id>_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. |
| | |
| | <code php> |
| | 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'); |
| | </code> |
| | |
| | ---- |
| | |
| | ===== 11. Module-specific (not part of the generic vocabulary) ===== |
| |
| ^ Hook ^ Type ^ Args ^ Dispatched from ^ | ^ Hook ^ Type ^ Args ^ Dispatched from ^ |
| | ''category_report_enabled'' | ''Filter<bool>'' | ''(bool $enabled)'' | ''category_report.php'' | | | ''category_report_enabled'' | ''Filter<bool>'' | ''(bool $enabled)'' | ''category_report.php'' | |
| | ''category_report_config'' | ''Filter<array>'' | ''(array $config)'' | ''category_report.php'' | | | ''category_report_config'' | ''Filter<array>'' | ''(array $config)'' | ''CategoryReportPresenter'' | |
| |
| Kept deliberately module-specific: ''category_report_config'' is genuine module data with no generic | Kept deliberately module-specific: ''category_report_config'' is genuine module data with no generic |
| |
| <code php> | <code php> |
| | Hooks::DEFAULT_PRIORITY // 10 |
| | |
| Hooks::addAction(string $name, callable $callback, int $priority = 10, ?int $acceptedArgs = null, ?string $id = null): void | Hooks::addAction(string $name, callable $callback, int $priority = 10, ?int $acceptedArgs = null, ?string $id = null): void |
| Hooks::doAction(string $name, mixed ...$args): void | Hooks::doAction(string $name, mixed ...$args): void |
| Hooks::doActionCatchErrors(string $name, mixed ...$args): void // failure/diagnostic dispatch only | 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::addFilter(string $name, callable $callback, int $priority = 10, ?int $acceptedArgs = null, ?string $id = null): void |
| </code> | </code> |
| |
| Lower priority runs earlier; same priority runs in registration order. A callback throws to veto an | Lower priority runs earlier; same priority runs in registration order. An explicit ''$id'' is unique within |
| Action or a Filter; the exception propagates. ''doActionCatchErrors()'' logs and swallows instead, used | one hook regardless of the priority: registering the same ID again replaces the earlier registration, and |
| only at failure/diagnostic sites where the original failure must stay the one Admidio reports. | ''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 | ''doAction()''/''doActionCatchErrors()''/''applyFilters()''/''applyTypedFilters()''/''resolve()'' are not only for |
| extensible by other plugins the same way core is — register the names with ''add*()'' as usual, then | 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. | 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. |
| | |
| | <code php> |
| | ChangelogService::registerCallback(string $function, string $moduleOrKey, mixed $callback): void |
| | </code> |
| | |
| | ''$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. |
| | |
| | <code php> |
| | 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')); |
| | </code> |
| | |
| | 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). |
| |