Skip to content
Display

Display

Star12.2k

Developers

Events and filters (hooks) reference

Markdown

Leantime lets plugins react to what happens in the app and change data on its way through, without editing core code. There are two kinds of hooks:

  • Events tell you that something happened, for example a to-do was created. Your listener runs; its return value is ignored.
  • Filters pass a value through your listener before Leantime uses it, for example the list of menu items. Your listener must return the value, changed or not.

This page covers Leantime 3.17. Register listeners in your plugin’s register.php (see Plugin development).

Use the class-based events and filters first. Each one is a PHP class in app/Domain/{Domain}/Events/, with typed properties and a docblock that says when it fires. Their names don’t change when core code moves.

Use string hooks for everything else. Their names are built from the class and method that fires them (see How are string hook names built?), so they change when core code is moved or renamed. Core is moving them to classes over time.

Pass the class name. Your listener gets the event object:

<?php
use Leantime\Core\Events\EventDispatcher;
use Leantime\Domain\Tickets\Events\TicketCompleted;
EventDispatcher::add_event_listener(TicketCompleted::class, function (TicketCompleted $event): void {
// $event->ticketId, $event->projectId, $event->wasOverdue, ...
});

You can also pass a class name instead of a closure: add_event_listener(TicketCompleted::class, MyListener::class). Leantime builds MyListener from the container and calls its handle(TicketCompleted $event) method.

Your listener gets the value and the filter object, and returns the value:

<?php
use Leantime\Core\Events\EventDispatcher;
use Leantime\Domain\Calendar\Events\CalendarProvidersFilter;
EventDispatcher::add_filter_listener(CalendarProvidersFilter::class, function (array $providers, CalendarProvidersFilter $filter): array {
$providers[] = [
'id' => 'mycalendar',
'icon' => 'fa fa-calendar',
'title' => __('mycalendar.title'),
'description' => __('mycalendar.description'),
'actionUrl' => BASE_URL.'/mycalendar/connect',
'actionLabel' => __('mycalendar.connect'),
'actionType' => 'modal',
];
return $providers;
});

All of these are in Leantime\Domain\{Domain}\Events. The properties listed are public and read-only.

Event Fires after Properties
Api\Events\ApiKeyCreated An API key was created apiUserId
Api\Events\ApiMethodCalled A JSON-RPC call from an API key, Bearer token or MCP client succeeded (not the web app’s own calls) method, channel
Auth\Events\LoginSucceeded Someone signed in (after the second factor, when two-factor authentication is on) userId, method
Auth\Events\OnboardingCompleted An invited user finished the welcome steps userId
Auth\Events\UserRegistered An invited user finished setting up their account and was activated userId
Blueprints\Events\CanvasCreated A board was created on any canvas type, including copies and imports (not Docs) canvasId, type, projectId
Blueprints\Events\CanvasItemCreated An item was created on any canvas type, including goals and ideas (not Docs) canvasItemId, type, projectId
Blueprints\Events\CanvasItemUpdated An item on any canvas type was updated canvasItemId, changedFields (fields that may have changed)
Calendar\Events\CalendarConnected Someone created their iCal feed link or added an external calendar kind
Calendar\Events\CalendarEventCreated A calendar event was created eventId, allDay
Calendar\Events\CalendarEventUpdated A calendar event was edited, moved or resized eventId
Calendar\Events\CalendarEventDeleted A calendar event was deleted eventId
Comments\Events\CommentAdded A comment was saved on anything commentId, module, moduleId, projectId, isReply, hasMention
Files\Events\FileUploaded A file was uploaded fileId, module, moduleId, extension, size
Goalcanvas\Events\GoalProgressUpdated A goal’s current value changed goalId, projectId, previousValue, currentValue, endValue, targetReached
Notifications\Events\PushDeviceRegistered A mobile device registered for push notifications userId, platform
Notifications\Events\UserMentioned A mentioned person was notified (once per person) mentionedUserId, module, moduleId, projectId
Plugins\Events\PluginInstalled A plugin was installed plugin, format
Plugins\Events\PluginEnabled A plugin was enabled plugin
Plugins\Events\PluginDisabled A plugin was disabled plugin
Projects\Events\ProjectCreated A project was created (not duplicated) projectId, type
Projects\Events\ProjectArchived A project was closed projectId
Projects\Events\ProjectMemberAdded Someone was added to a project team projectId, userId
Projects\Events\ProjectStatusUpdatePosted A project status update was posted (CommentAdded fires too) projectId, commentId, status
Projects\Events\ProjectFavoriteAdded Someone marked a project as a favorite projectId, userId
Projects\Events\ProjectFavoriteRemoved Someone removed a project from their favorites projectId, userId
Reminders\Events\ReminderDefaultsUpdated Someone changed their reminder defaults userId
Reminders\Events\TaskReminderUpdated Someone changed the reminder on one to-do ticketId, userId
Sprints\Events\SprintCreated A sprint was created sprintId, projectId, lengthDays
Tickets\Events\TicketCreated A to-do or subtask was created ticketId, origin, type, hasDueDate, assignedToOther, projectId
Tickets\Events\TicketUpdated A to-do or subtask was updated (ticketId is null for bulk changes such as sorting) ticketId
Tickets\Events\TicketDeleted A to-do was deleted ticketId
Tickets\Events\TicketAssigned A to-do got a new assignee ticketId, projectId, assigneeId, previousAssigneeId, assignedToSelf
Tickets\Events\TicketCompleted A to-do moved into a done status ticketId, projectId, type, completedByAssignee, daysToComplete, hadDueDate, wasOverdue, wasScheduledToday
Tickets\Events\TicketScheduled A to-do’s planned work time was set or moved ticketId, projectId, editFrom, editTo, rescheduled
Tickets\Events\TicketStatusUpdated A to-do’s status changed, for example on the Kanban board ticketId, status, handler
Tickets\Events\SubtasksUpdated A subtask was added, edited or deleted parentTicketId
Tickets\Events\MilestoneCreated A milestone was created milestoneId, origin, projectId
Tickets\Events\MilestoneUpdated A milestone was updated milestoneId, projectId
Tickets\Events\MilestoneDeleted A milestone was deleted milestoneId
Tickets\Events\StatusLabelsUpdated A project’s status labels were saved projectId
Timesheets\Events\TimeEntryCreated A new timesheet row was created (adding hours to an existing row doesn’t fire it) ticketId, hours, projectId
Timesheets\Events\TimerStarted Someone started a timer on a to-do ticketId
Timesheets\Events\TimerStopped A running timer was stopped and its time logged ticketId, hours, automatic
TwoFA\Events\TwoFactorEnabled Someone turned on two-factor authentication userId
Users\Events\UserCreated A user account was created, from any path userId, role, source
Users\Events\InviteSent An invitation email was sent or resent userId
Users\Events\AppearanceUpdated Someone changed their theme, color mode, color scheme or font userId, theme, colorMode, colorScheme, font
Widgets\Events\DashboardWidgetAdded A widget was added to someone’s dashboard widgetId
Wiki\Events\WikiArticleCreated A Docs article was created articleId, projectId
Filter Filters Value passed through
Calendar\Events\CalendarProvidersFilter The providers in the Connect Calendar dialog array $providers
Calendar\Events\CalendarSettingsSectionsFilter Plugin sections in the calendar settings dialog array $sections
Calendar\Events\ExternalCalendarsFilter External calendars on the calendar page and in calendar settings ($filter->inSettings says which) array $calendars
Tickets\Events\TicketListFilter The grouped to-do list before the list and table views show it array $tickets
Tickets\Events\TodoWidgetTasksFilter Your to-dos before the My To-Dos widget shows them array $tickets

Each class’s docblock describes the array format. Read them in app/Domain on GitHub.

Most string hooks are fired with dispatch_event() / dispatchEvent() or dispatch_filter() / dispatchFilter() from a class that uses the DispatchesEvents trait. The full name has three parts:

leantime.domain.tickets.services.tickets . updateTicket . ticket_updated
└──── class namespace, lowercase ───────┘ └ method ┘ └─ hook name ─┘
  1. The class’s full name with \ replaced by ., all lowercase: Leantime\Domain\Tickets\Services\Tickets becomes leantime.domain.tickets.services.tickets.
  2. The method that fired it, case kept: updateTicket.
  3. The hook name passed to the dispatch call, case kept: ticket_updated.

A few calls pass their own prefix instead. For example, LoadPlugins fires pluginsEvents with the prefix leantime.core.middleware.loadplugins.handle. Read the call to be sure.

A listener that uses the wrong case never runs. There is no error.

Templates fire hooks with @dispatchEvent('name') and @dispatchFilter('name', $value) in Blade, or $tpl->dispatchTplEvent() and $tpl->dispatchTplFilter() in older .tpl.php files. Their names start with the page being shown, not the file the hook is in:

leantime.domain.{module}.templates.{view}.{hook name}

For example, the to-do table page (tickets.showAll) fires leantime.domain.tickets.templates.showAll.allTicketsTable.beforeRowEnd. Pages from a plugin start with leantime.plugins.{plugin}.templates. instead.

Hooks in the shared layout, such as afterLinkTags in the page head, fire on every page under that page’s name. Listen with a wildcard: leantime.*.afterLinkTags.

Listener names can contain patterns:

  • * matches any text, including dots: leantime.*.beforeBodyClose
  • ? matches one character
  • {RGX:pattern:RGX} inserts a regular expression
<?php
use Leantime\Core\Events\EventDispatcher;
// Event: one array with the hook's data, plus current_route and currentEvent
EventDispatcher::add_event_listener(
'leantime.domain.projects.services.projects.duplicateProject.projectDuplicated',
function (array $params): void {
// $params['projectId'], $params['newProjectId']
}
);
// Filter: the value, plus an array of extra data. Return the value.
EventDispatcher::add_filter_listener(
'leantime.domain.menu.repositories.menu.getMenuStructure.menuStructures.personal',
function (array $menu, array $params): array {
return $menu;
},
50 // priority: lower numbers run first; the default is 10
);

Every name in this table exists in Leantime 3.17.

Hook Type Use it to
leantime.core.console.consolekernel.schedule.cron Event Add scheduled jobs. $params['schedule'] is Laravel’s Schedule.
leantime.core.middleware.loadplugins.handle.pluginsEvents Event Run early setup on every request, after plugins are loaded.
leantime.core.middleware.authcheck.__construct.publicActions Filter Make routes reachable without signing in. Add the first two URL segments joined by a dot, such as helloworld.status for /helloworld/status.
leantime.core.middleware.initialheaders.handle.cspParts Filter Change the Content-Security-Policy, for example to allow an outside script.
leantime.core.http.httpkernel.handle.beforeSendResponse Filter Change any response before it’s sent.
leantime.domain.menu.repositories.menu.getMenuStructure.menuStructures.{menu} Filter Change a menu: personal, company, projecthub or default (the project menu). Registration::addMenuItem() uses this.
leantime.domain.widgets.services.widgets.__construct.availableWidgets Filter Add dashboard widgets.
leantime.domain.search.services.search.getProviders.providers Filter Add search providers.
leantime.domain.connector.services.providers.loadProviders.providerList Filter Add import sources to Integrations.
leantime.domain.auth.models.roles.getFilteredRoles.available_roles Filter Change the role names offered.
leantime.domain.projects.services.projects.notifyProjectUsers.notifyProjectUsers Event React to project notifications (type, message, subject, users, URL).
leantime.domain.projects.services.projects.duplicateProject.projectDuplicated Event React to a copied project (projectId, newProjectId).
leantime.domain.users.services.users.editUser.editUser Event React to an admin editing a user (id, values).
leantime.domain.modulemanager.services.modulemanager.saveProjectModules.projectModulesSaved Event React to a project’s Modules being saved (projectId, modules).
leantime.*.afterLinkTags Event Print tags into the page head. addCss() and addHeaderJs() use this.
leantime.*.beforeBodyClose Event Print scripts at the end of the page. addFooterJs() uses this.
leantime.*.page_title Filter Change the browser tab title.

Some class-based events also fire their old string name, so older plugins keep working. For example, TicketUpdated from updateTicket() also fires leantime.domain.tickets.services.tickets.updateTicket.ticket_updated. The class’s legacyHooks() method shows the old name. These names will be removed, so listen to the class instead.

Search the Leantime source. From the Leantime folder:

Terminal window
# String hooks fired from PHP classes
grep -rnE "dispatch_?(event|Event|filter|Filter)\(" app/Core app/Domain
# Hooks in templates
grep -rnE "@dispatch(Event|Filter)|dispatchTpl(Event|Filter)" app/Domain app/Views
# Class-based events and filters
ls app/Domain/*/Events/

For each string hook you find, build the name from the class, the method and the hook name as described above. Check whether the call passes its own prefix as the last argument.

To see which names actually fire, log them from a wildcard listener while you click through the page:

use Illuminate\Support\Facades\Log;
use Leantime\Core\Events\EventDispatcher;
EventDispatcher::add_event_listener('leantime.domain.tickets.*', function (array $params): void {
Log::debug($params['currentEvent']);
});

Remove it when you’re done: it runs on every matching event.

Was this page helpful?