Hi,
I try to build a custom field that is readonly for all users except one defined in another field of the same page. I tried to do this in the constructor like this:
class ApprovecontentField extends SelectField {
public function __construct() {
$this->type = 'select';
// Get the defined user with access
$designatedApprover = $this->page()->contentapprover();
$currentUser = kirby()->site()->user()->username();
// Lock the field if user is not the one set for approval
$this->readonly = $currentUser == $designatedApprover ? false : true;
$this->options = array();
$this->icon = 'chevron-down';
}
}
However it seems I have no access to $this->page()
inside the constructor. What is the best way to achieve this?
Kind regards,
Georg