When i save a page in the panel, i would like to save the current content of that page to all of it’s language files. independently of the current language.
In the following simplified page model, i am overwriting the writeContent-Method.
I tried $this-save()
with a different language, but that leads to an endless loop, cause writeContent will be called again and again…
i also tried to call parent::writeContent
with ‘en’. That works, but that seems a bit hackisch.
Does anyone maybe knows a good/better solution for that edge case?
Thx!
class MessagePage extends Page
{
public function writeContent(array $data, string $languageCode = null): bool
{
if ($id = Db::insert('message', [
'slug' => $this->slug(),
....
])) {
// $this.save($data, 'en', true); -> endless loop
$enPage = parent::writeContent($data, 'en');
return parent::writeContent($data, $languageCode);
} else {
throw new Exception('Error');
};
}
}