-
-
Notifications
You must be signed in to change notification settings - Fork 186
Closed
Milestone
Description
I use a page model to instantiate objects based on current content state.
Describe the bug
Upon page update, the content state in a page model does not get updated.
To Reproduce
- Add the text 'before update' into the text field on the home page
- Extend the home page PageModel and add a page.update:after hook
<?php
use Kirby\Cms\Page;
class HomePage extends Page {
protected $myText;
protected $uniqId;
public function __construct(array $props)
{
parent::__construct($props);
$this->myText = $this->content()->text();
$this->uniqId = uniqid();
}
public function getMyText() {
return $this->myText;
}
public function getUniqId() {
return $this->uniqId;
}
}// site/config/config.php
return [
'debug' => true,
'hooks' => [
'page.update:after' => function ($newPage, $oldPage) {
error_log("uniqid: new:" . $newPage->getUniqId() . " old:" . $oldPage->getUniqId() . " text: new:" . $newPage->getMyText() . " old:" . $oldPage->getMyText());
}
]
];- In the panel: Edit the text field on the home page to 'after update'
- See output in your error_log:
uniqid: new:5e91d593705de old:5e91d5936f4d4 text: new:before update old:before update
note that the uniqid has changed, myText didn't.
same if I try to update the page in a template:
$oldPage = page('home');
$newPage = $oldPage->update(['text' => 'after update']);
error_log("uniqid: new:" . $newPage->getUniqId() . " old:" . $oldPage->getUniqId() . " text: new:" . $newPage->getMyText() . " old:" . $oldPage->getMyText());Expected behavior
I'd expect the property myText also to change. Therefore the log should be
uniqid: new:5e91d593705de old:5e91d5936f4d4 text: new:after update old:before update
Kirby Version
3.3.5
Metadata
Metadata
Assignees
Labels
No labels