Events Reference
Events serve as a great way to decouple various aspects of your addon, or even modify behavior or output of core functionality. A single event can have multiple listeners that do not depend on each other.
Overview
Simpler events are provided as a string with an argument passed through as a payload. For example, the cp.page.published
event is dispatched as a string, and passes along the Page
that was published.
public $events = [
'cp.page.published' => 'doSomething'
];
public function doSomething($entry)
{
//
}
Potentially more complicated events are provided as an event class. For example, when a page is deleted, the Statamic\Events\Data\PageDeleted
class is dispatched. This class will be provided as the argument.
use Statamic\Events\Data\PageDeleted;
...
public $events = [
PageDeleted::class => 'doSomething'
];
public function doSomething(PageDeleted $event)
{
//
}
Laravel Events
Statamic provides its own events, however you are free to also listen for any Laravel events such as auth.login
and auth.logout
.
Data Events
Statamic will dispatch a number of “Data Events” when things are modified throughout the system. Typically these are for things that would affect items in the filesystem. For example, when a page is saved, deleted, or moved; or when settings are updated.
All of these events make two methods available to you:
public function handle($event)
{
$event->affectedPaths();
// An array of file paths that have been affected by the action.
// For example:
// [
// /path/to/content/pages/oldpageslug/index.md,
// /path/to/content/pages/newpageslug/index.md
// ]
$event->contextualData();
// An array representation of the item that was saved.
// For example, the data in a page, or an array of configuration settings.
}
Events
cp.add_to_head | cp.add_to_head | |
cp.nav.created | cp.nav.created | |
cp.published | cp.published | |
Form.submission.created | Form.submission.created | |
Form.submission.creating | Form.submission.creating | |
glide.generated | glide.generated | |
response.created | response.created | |
AddonSettingsSaved | Statamic\Events\Data\AddonSettingsSaved | |
AssetContainerDeleted | Statamic\Events\Data\AssetContainerDeleted | |
AssetContainerSaved | Statamic\Events\Data\AssetContainerSaved | |
AssetDeleted | Statamic\Events\Data\AssetDeleted | |
AssetFolderDeleted | Statamic\Events\Data\AssetFolderDeleted | |
AssetFolderSaved | Statamic\Events\Data\AssetFolderSaved | |
AssetMoved | Statamic\Events\Data\AssetMoved | |
AssetReplaced | Statamic\Events\Data\AssetReplaced | |
AssetUploaded | Statamic\Events\Data\AssetUploaded | |
CollectionDeleted | Statamic\Events\Data\CollectionDeleted | |
CollectionSaved | Statamic\Events\Data\CollectionSaved | |
ContentDeleted | Statamic\Events\Data\ContentDeleted | |
ContentSaved | Statamic\Events\Data\ContentSaved | |
EntryDeleted | Statamic\Events\Data\EntryDeleted | |
EntrySaved | Statamic\Events\Data\EntrySaved | |
FieldsetDeleted | Statamic\Events\Data\FieldsetDeleted | |
FieldsetSaved | Statamic\Events\Data\FieldsetSaved | |
FileUploaded | Statamic\Events\Data\FileUploaded | |
FindingFieldset | Statamic\Events\Data\FindingFieldset | |
GlobalsDeleted | Statamic\Events\Data\GlobalsDeleted | |
GlobalsSaved | Statamic\Events\Data\GlobalsSaved | |
PageDeleted | Statamic\Events\Data\PageDeleted | |
PageMoved | Statamic\Events\Data\PageMoved | |
PageSaved | Statamic\Events\Data\PageSaved | |
PagesMoved | Statamic\Events\Data\PagesMoved | |
PublishFieldsetFound | Statamic\Events\Data\PublishFieldsetFound | |
RoleDeleted | Statamic\Events\Data\RoleDeleted | |
RoleSaved | Statamic\Events\Data\RoleSaved | |
SettingsSaved | Statamic\Events\Data\SettingsSaved | |
SubmissionDeleted | Statamic\Events\Data\SubmissionDeleted | |
SubmissionSaved | Statamic\Events\Data\SubmissionSaved | |
TaxonomyDeleted | Statamic\Events\Data\TaxonomyDeleted | |
TaxonomySaved | Statamic\Events\Data\TaxonomySaved | |
TermDeleted | Statamic\Events\Data\TermDeleted | |
TermSaved | Statamic\Events\Data\TermSaved | |
UserDeleted | Statamic\Events\Data\UserDeleted | |
UserGroupDeleted | Statamic\Events\Data\UserGroupDeleted | |
UserGroupSaved | Statamic\Events\Data\UserGroupSaved | |
UserSaved | Statamic\Events\Data\UserSaved | |
SearchQueryPerformed | Statamic\Events\SearchQueryPerformed | |
StacheUpdated | Statamic\Events\StacheUpdated | |
StatamicUpdated | Statamic\Events\StatamicUpdated | |
user.registered | user.registered | |
content.saved | content.saved | Deprecated |
system.updated | system.updated | Deprecated |