Event or callback when a stack is created

Permalink
What would be the callback or event for the stack creation. I want to be notified whenever a stack is created. I need a webhook for stack creation so that I can be notified on some other server.

 
hutman replied on at Permalink Reply
hutman
I do not believe one exists for this yet. Here is a list of all of the current events that are fired https://documentation.concrete5.org/developers/application-events/fu...
mnakalay replied on at Permalink Best Answer Reply
mnakalay
Actually there is.

Stacks are really pages so you can use the on_page_add event. When you hook on that event and get the newly added page object, you get the type and the type's handle and if the handle is equal to STACKS_PAGE_TYPE you know that was a stack

So
$ptHandle = $page->getCollectionTypeHandle();
// Or $ptHandle = $page->getPageTypeHandle();
// they both work, one just returns the other
if ($ptHandle == STACKS_PAGE_TYPE) {
    // it is a stack
}
nancyimpinge replied on at Permalink Reply
Thanks Guys for your response. As mentioned in the event list, there is an event - on_page_add. As i am new to concrete, can you please mention the way we can implement this event.

Where should I call this event in the code?
nancyimpinge replied on at Permalink Reply
Okay got it.
Write following code:
Events::addListener('on_page_add', function($event) {
//do required
});

in /application/bootstrap/app.php