$html_page = new CHtmlPage();
if ($data['parent_discoveryid'] === null) {
->setDocUrl(CDocHelper::getUrl(CDocHelper::DATA_COLLECTION_GRAPH_EDIT))
->setNavigation(getHostNavigation('graphs', $data['hostid']));
->setTitle(_('Graph prototypes'))
->setDocUrl(CDocHelper::getUrl(CDocHelper::DATA_COLLECTION_PROTOTYPE_GRAPH_EDIT))
->setNavigation(getHostNavigation('graphs', $data['hostid'], $data['parent_discoveryid']));
$url = (new CUrl('graphs.php'))
->setArgument('parent_discoveryid', $data['parent_discoveryid'])
->setArgument('context', $data['context'])
$graphForm = (new CForm('post', $url))
->addItem((new CVar(CSRF_TOKEN_NAME, CCsrfTokenHelper::get('graphs.php')))->removeId())
->addItem((new CVar('form_refresh', $data['form_refresh'] + 1))->removeId())
->setAttribute('aria-labelledby', CHtmlPage::PAGE_TITLE_ID)
->addVar('form', $data['form'])
->addVar('hostid', $data['hostid']);
if ($data['parent_discoveryid'] !== null) {
$graphForm->addItem((new CVar('parent_discoveryid', $data['parent_discoveryid']))->removeId());
if ($data['graphid'] != 0) {
$graphForm->addVar('graphid', $data['graphid']);
$graphFormList = new CFormList('graphFormList');
$is_templated = (bool) $data['templates'];
$graphFormList->addRow(_('Parent graphs'), $data['templates']);
$discovered_graph = false;
if (array_key_exists('flags', $data) && $data['flags'] == ZBX_FLAG_DISCOVERY_CREATED) {
$discovered_graph = true;
if ($is_templated || $discovered_graph) {
$graphForm->addItem((new CVar('readonly', 1))->removeId());
$graphFormList->addRow(_('Discovered by'), new CLink($data['discoveryRule']['name'],
->setArgument('form', 'update')
->setArgument('parent_discoveryid', $data['discoveryRule']['itemid'])
->setArgument('graphid', $data['graphDiscovery']['parent_graphid'])
->setArgument('context', $data['context'])
(new CLabel(_('Name'), 'name'))->setAsteriskMark(),
(new CTextBox('name', $data['name'], $readonly, DB::getFieldLength('graphs', 'name')))