Page Module
The page module comes with the following hooks. You can hook into those using the usual listener logic.
Please view the hook section in the Core module.
The PageIsUpdating
has one more method:
getPage()
: Will return the page being updatedTo keep the example simple we're going to use an inline listener using a closure instead of a full class.
Lets say you want to upper case the page titles:
Event::listen(PageIsUpdating::class, function (PageIsUpdating $event) {
$attributes = [
'en' => ['title' => strtoupper($this->getAttributes('en.title'))]
'fr' => ['title' => strtoupper($this->getAttributes('fr.title'))]
];
$event->setAttributes($attributes);
});
This hook is used in the body Accessor of a page. Every time you'll call $page->body
this hook will be triggered. You can still use ->getOriginal('body')
on the PageTranslation entity like any laravel model to bypass this accessor.
Available methods:
getBody()
: Will return the current body contentsetBody('')
: Sets the body elementgetOriginal()
: Get the original body without any changes by other listenersYou could use this hook to add short codes to your page body section for example.
Event::listen(ContentIsRendering::class, function (ContentIsRendering $event) {
$content = str_replace('[shortcode]', 'My Awesome Code', $event->getBody();
$event->setBody($content);
});