setPostContentType(self::POST_CONTENT_TYPE_JSON); $this->disableCsrfValidation(); $this->setValidationRules([ 'name' => 'string', 'fields' => 'array', 'templateid' => 'db dashboard.templateid' ]); } protected function setValidationRules(array $validation_rules): self { $this->validation_rules = $validation_rules; return $this; } protected function addValidationRules(array $validation_rules): self { $this->validation_rules = array_merge($this->validation_rules, $validation_rules); return $this; } protected function checkPermissions(): bool { return $this->getUserType() >= USER_TYPE_ZABBIX_USER; } protected function checkInput(): bool { $this->widget = APP::ModuleManager()->getActionModule(); $validation_rules = $this->validation_rules; $ret = $this->validateInput($validation_rules); if ($ret) { $this->form = $this->widget->getForm($this->getInput('fields', []), $this->hasInput('templateid') ? $this->getInput('templateid') : null ); if ($errors = $this->form->validate()) { foreach ($errors as $error) { error($error); } $ret = false; } } if ($ret) { $this->fields_values = $this->form->getFieldsValues(); } if (!$ret) { $this->setResponse( (new CControllerResponseData(['main_block' => json_encode([ 'error' => [ 'messages' => array_column(get_and_clear_messages(), 'message') ] ], JSON_THROW_ON_ERROR)]))->disableView() ); } return $ret; } protected function getForm(): CWidgetForm { return $this->form; } protected function doAction(): void { $this->setResponse(new CControllerResponseData([ 'name' => $this->getInput('name', $this->widget->getName()), 'user' => [ 'debug_mode' => $this->getDebugMode() ] ])); } protected function isTemplateDashboard(): bool { return $this->hasInput('templateid'); } }