name = $name; $this->label = $label; $this->type = $type; $this->permission = $permission; } public function checkPermission():bool { if (is_bool($this->permission)) { return $this->permission; } if (is_string($this->permission)) { return current_user_can($this->permission); } if (is_callable($this->permission)) { return ($this->permission)(); } error_log('Check Permission failed as no permission set. '.print_r([ 'permission' => $this->permission, 'field' => $this->name, ], true)); return false; } public function setRequired():void { $this->required = true; } public function setOptions(array $options):void { $this->options = $options; } public function getConfig():array { $conf = [ 'name' => $this->name, 'label' => $this->label, 'type' => $this->type, ]; if ($this->required) { $conf['required'] = true; } if ($this->options) { $conf['options'] = $this->options; } return $conf; } }