I have a Page Model with a custom computed field bar
which returns some computed data based on the content of this page.
class FooPage extends Page {
public function bar() {
return "foobar";
}
}
Can I include this result from bar()
into my panel search?
The use case for example could be a select field with custom label mappings coming from a config file. I now want to search pages for the selected labels.
Iām just guessing, but you might want to include your bar
value into the page content
.
Something like:
class FooPage extends Page {
public function bar() {
return "foobar";
}
public function content(string $languageCode = null) {
$content = parent::content($languageCode);
return $content->update(['bar' => $this->bar()]);
}
}
1 Like
thanks, it (almost) works.
i found that accessing actual content fields within the content()
method is not possible via __call syntax since it creates an infinite loop.
so i had to access the \Kirby\Cms\Content
object directly
class FooPage extends Page {
public function bar() {
return "foobar";
}
public function content(string $languageCode = null) {
$content = parent::content($languageCode);
$childContentBefore = $this->content;
// work with $content->get("propertyName") instead of accessing properties with $this->propertyName() to avoid infinite loop
return $content->update(['bar' => $this->bar()]);
}
}
1 Like