To answer this question I think you need to be a really good friend with the Kirby Panel core.
In a custom field there is an input()
function where I call a template.php
file. In that file I do this:
$form = (string)new Form($fields, $values);
echo $form;
For many cases it works fine, but for fields that uses the $page
object, it does not work.
I found out that it comes down to that the base
field is not aware of the $page
object. I can’t figure out why and I can’t squeeze it in there.
My ugly workaround
input function of my custom field
I set the page id as a global variable.
kirby()->set('option', 'page.id', $this->page->id());
base-field
I register a base-field (replacing the old one) that is a a copy of the original. Then I add a constructor where I set the page object to the global variable.
public function __construct() {
$this->page = page(kirby()->get('option', 'page.id'));
}
While it works, I think it’s an ugly solution. If a new Kirby version comes out, maybe the base-field has been updated and that would cause problem.
I’ve been trying to solve this issue for 1 day now without success. Any ideas would be helpful.