Files
zoneminder/web/includes/MenuItem.php
Isaac Connor 48fadaebbf feat: customizable menu entries with links, icons and delete on options menu tab
Port the menu customization work from the ai_server branch onto master:
- Add/edit/delete custom navbar/sidebar menu entries via Options > Menu
- Per-entry Link column (new Menu_Items.Link) with ?view= fallback derived
  the same way as built-in items; custom entries render via buildMenuItem
- Live icon preview (material/font awesome) with fixed-width preview cell
- Per-row delete icon; add/reset buttons with tooltips
- Surface DB errors when saving options config: capture the swallowed PDO
  error via dbLastError() and show it in the page error banner instead of
  redirecting past it

Menu_Items.Link is added to zm_create.sql.in and as an idempotent ALTER in
zm_update-1.39.16.sql.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-27 12:13:49 -04:00

70 lines
1.9 KiB
PHP

<?php
namespace ZM;
require_once('database.php');
require_once('Object.php');
class MenuItem extends ZM_Object {
protected static $table = 'Menu_Items';
protected $defaults = array(
'Id' => null,
'MenuKey' => '',
'Enabled' => 1,
'Label' => null,
'SortOrder' => 0,
'Icon' => null,
'IconType' => 'material',
'Link' => null,
);
// Default material icons for each menu key
public static $defaultIcons = array(
'Console' => 'dashboard',
'Montage' => 'live_tv',
'MontageReview' => 'movie',
'Events' => 'event',
'Options' => 'settings',
'Log' => 'notification_important',
'Devices' => 'devices_other',
'IntelGpu' => 'memory',
'Groups' => 'group',
'Filters' => 'filter_alt',
'Snapshots' => 'preview',
'Reports' => 'report',
'ReportEventAudit' => 'shield',
'Map' => 'language',
);
public function effectiveIcon() {
if ($this->{'Icon'} !== null && $this->{'Icon'} !== '') {
return $this->{'Icon'};
}
return isset(self::$defaultIcons[$this->{'MenuKey'}]) ? self::$defaultIcons[$this->{'MenuKey'}] : 'menu';
}
public function effectiveIconType() {
if ($this->{'IconType'} == 'none') {
return 'none';
}
if ($this->{'Icon'} !== null && $this->{'Icon'} !== '') {
return $this->{'IconType'};
}
return 'material';
}
public static function find($parameters = array(), $options = array()) {
return ZM_Object::_find(self::class, $parameters, $options);
}
public static function find_one($parameters = array(), $options = array()) {
return ZM_Object::_find_one(self::class, $parameters, $options);
}
public function displayLabel() {
if ($this->{'Label'} !== null && $this->{'Label'} !== '') {
return $this->{'Label'};
}
return translate($this->{'MenuKey'});
}
}