Source
<?php declare(strict_types = 0);
/*
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
** without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
** See the GNU Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
use Zabbix\Core\{
CModule,
CWidget
};
use \Zabbix\Widgets\CWidgetField;
class CControllerDashboardWidgetEdit extends CController {
private ?CWidget $widget;
protected function init(): void {
$this->disableCsrfValidation();
}
protected function checkInput(): bool {
$fields = [
'type' => 'string|required',
'fields' => 'array',
'templateid' => 'db dashboard.templateid',
'name' => 'string',
'view_mode' => 'in '.implode(',', [ZBX_WIDGET_VIEW_MODE_NORMAL, ZBX_WIDGET_VIEW_MODE_HIDDEN_HEADER]),
'unique_id' => 'string',
'dashboard_page_unique_id' => 'string'
];
$ret = $this->validateInput($fields);
if ($ret) {
/** @var CWidget $widget */
$widget = APP::ModuleManager()->getModule($this->getInput('type'));
if ($widget !== null && $widget->getType() === CModule::TYPE_WIDGET) {
$this->widget = $widget;
}
else {
error(_('Inaccessible widget type.'));
$ret = false;
}
}
if (!$ret) {
$this->setResponse(
(new CControllerResponseData([
'main_block' => json_encode([
'header' => $this->hasInput('unique_id') ? _('Edit widget') : _('Add widget'),