Source
xxxxxxxxxx
* Reference is needed here to avoid array merging in CWidgetForm::fieldsToApi method. With large number of widget
<?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/>.
**/
namespace Zabbix\Widgets;
use CApiInputValidator,
DB;
abstract class CWidgetField {
public const DEFAULT_VIEW = null;
public const FLAG_NOT_EMPTY = 0x02;
public const FLAG_LABEL_ASTERISK = 0x04;
public const FLAG_DISABLED = 0x08;
public const FOREIGN_REFERENCE_KEY = '_reference';
public const REFERENCE_DASHBOARD = 'DASHBOARD';
protected string $name;
protected ?string $label;
protected ?string $label_prefix = null;
protected ?int $save_type = null;
protected $value;
protected $default;
protected array $values_captions = [];
protected string $inaccessible_caption = '';
protected int $max_length;
protected ?string $action = null;
protected int $flags = 0x00;
private array $validation_rules = [];
private $templateid = null;
private bool $default_prevented = false;
private bool $widget_accepted = false;
private bool $dashboard_accepted = false;
private string $in_type = '';
/**
* @param string $name Field name in form.
* @param string|null $label Label for the field in form.
*/
public function __construct(string $name, ?string $label = null) {
$this->name = $name;
$this->label = $label;
$this->value = null;
$this->setSaveType(ZBX_WIDGET_FIELD_TYPE_STR);
}
public function getName(): string {
return $this->name;
}
public function getLabel(): ?string {
return $this->label;
}
/**
* Prefix field label to enhance clarity in case of error messages. For example:
* Invalid parameter "<LABEL PREFIX>: <LABEL>": too many decimal places.
*/
public function prefixLabel(?string $prefix): self {
$this->label_prefix = $prefix;
return $this;
}
/**
* Get fully qualified label for displaying in error messages.