diff --git a/resources/templates/navigation/tree/node.twig b/resources/templates/navigation/tree/node.twig index 46aec645c8..e9f6251a53 100644 --- a/resources/templates/navigation/tree/node.twig +++ b/resources/templates/navigation/tree/node.twig @@ -21,7 +21,7 @@ {% if node.isGroup %}
- {{ get_image(node.icon['image'], node.icon['title']) }} + {{ get_image(node.icon.image, node.icon.title) }}
 {{ node.name }} {% else %} diff --git a/src/Navigation/NavigationTree.php b/src/Navigation/NavigationTree.php index cb580fe280..df7230dae2 100644 --- a/src/Navigation/NavigationTree.php +++ b/src/Navigation/NavigationTree.php @@ -16,6 +16,7 @@ use PhpMyAdmin\Error\ErrorHandler; use PhpMyAdmin\Favorites\RecentFavoriteTables; use PhpMyAdmin\Favorites\TableType; use PhpMyAdmin\Html\Generator; +use PhpMyAdmin\Navigation\Nodes\Icon; use PhpMyAdmin\Navigation\Nodes\Node; use PhpMyAdmin\Navigation\Nodes\NodeColumn; use PhpMyAdmin\Navigation\Nodes\NodeColumnContainer; @@ -802,7 +803,12 @@ class NavigationTree $groups[$key] = new Node($this->config, (string) $key, NodeType::Container, true); $groups[$key]->separators = $node->separators; $groups[$key]->separatorDepth = $node->separatorDepth - 1; - $groups[$key]->icon = ['image' => 'b_group', 'title' => __('Groups')]; + $groups[$key]->icon = new Icon( + 'b_group', + __('Groups'), + $node->icon->route, + array_merge($node->icon->params, ['tbl_group' => $key]), + ); $groups[$key]->pos2 = $node->pos2; $groups[$key]->pos3 = $node->pos3; if ($node instanceof NodeTableContainer || $node instanceof NodeViewContainer) { @@ -811,10 +817,6 @@ class NavigationTree 'route' => $node->links['text']['route'], 'params' => array_merge($node->links['text']['params'], ['tbl_group' => $key]), ], - 'icon' => [ - 'route' => $node->links['icon']['route'], - 'params' => array_merge($node->links['icon']['params'], ['tbl_group' => $key]), - ], ]; } @@ -1016,6 +1018,8 @@ class NavigationTree $paths = $node->getPaths(); $nodeIsContainer = $node->type === NodeType::Container; $liClasses = ''; + $iconLinks = []; + $textLink = []; // Whether to show the node in the tree (true for all nodes but root) // If false, the node's children will still be shown, but as children of the node's parent @@ -1065,27 +1069,10 @@ class NavigationTree $args[$parent->urlParamName] = $parent->realName; } - $iconLinks = []; - $iconLinks[] = [ - 'route' => $node->links['icon']['route'], - 'params' => array_merge( - $node->links['icon']['params'], - array_intersect_key($args, $node->links['icon']['params']), - ), - 'image' => $node->icon['image'], - 'title' => $node->icon['title'], - ]; + $iconLinks[] = $node->icon->withDifferentParams($args); - if ($node instanceof NodeTable && isset($node->links['second_icon'], $node->secondIcon)) { - $iconLinks[] = [ - 'route' => $node->links['second_icon']['route'], - 'params' => array_merge( - $node->links['second_icon']['params'], - array_intersect_key($args, $node->links['second_icon']['params']), - ), - 'image' => $node->secondIcon['image'], - 'title' => $node->secondIcon['title'], - ]; + if ($node instanceof NodeTable && $node->secondIcon !== null) { + $iconLinks[] = $node->secondIcon->withDifferentParams($args); } $textLink = [ @@ -1136,8 +1123,8 @@ class NavigationTree 'node_is_container' => $nodeIsContainer, 'has_second_icon' => isset($node->secondIcon), 'recursive' => ['html' => $recursiveHtml ?? '', 'has_wrapper' => $wrap, 'is_hidden' => ! $node->visible], - 'icon_links' => $iconLinks ?? [], - 'text_link' => $textLink ?? [], + 'icon_links' => $iconLinks, + 'text_link' => $textLink, 'pagination_params' => $paginationParams, 'node_is_group' => $nodeIsGroup ?? false, 'link_classes' => $linkClasses ?? '', diff --git a/src/Navigation/Nodes/Icon.php b/src/Navigation/Nodes/Icon.php new file mode 100644 index 0000000000..b4acc869cf --- /dev/null +++ b/src/Navigation/Nodes/Icon.php @@ -0,0 +1,28 @@ + $params */ + public function __construct( + public string $image, + public string $title, + public string $route, + public array $params = [], + ) { + } + + /** @param array $params */ + public function withDifferentParams(array $params): self + { + $params = array_merge($this->params, array_intersect_key($params, $this->params)); + + return new self($this->image, $this->title, $this->route, $params); + } +} diff --git a/src/Navigation/Nodes/Node.php b/src/Navigation/Nodes/Node.php index 3041f162ad..2daa42ffe1 100644 --- a/src/Navigation/Nodes/Node.php +++ b/src/Navigation/Nodes/Node.php @@ -71,11 +71,8 @@ class Node /** * For the IMG tag, used when rendering the node. - * - * @var array - * @psalm-var array{image: string, title: string} */ - public array $icon = ['image' => '', 'title' => '']; + public Icon $icon; /** * An array of A tags, used when rendering the node. @@ -83,12 +80,10 @@ class Node * @var array * @psalm-var array{ * text: array{route: string, params: array}, - * icon: array{route: string, params: array}, - * second_icon?: array{route: string, params: array}, * title?: string * } */ - public array $links = ['text' => ['route' => '', 'params' => []], 'icon' => ['route' => '', 'params' => []]]; + public array $links = ['text' => ['route' => '', 'params' => []]]; /** @var string HTML title */ public string $title = ''; @@ -125,6 +120,7 @@ class Node public bool $isGroup = false, ) { $this->realName = $name; + $this->icon = new Icon('', '', ''); } /** diff --git a/src/Navigation/Nodes/NodeColumn.php b/src/Navigation/Nodes/NodeColumn.php index 06dbaf76c3..7afae81af8 100644 --- a/src/Navigation/Nodes/NodeColumn.php +++ b/src/Navigation/Nodes/NodeColumn.php @@ -27,16 +27,17 @@ class NodeColumn extends Node parent::__construct($config, $item['name']); - $this->icon = ['image' => $this->getColumnIcon($item['key']), 'title' => __('Column')]; + $this->icon = new Icon( + $this->getColumnIcon($item['key']), + __('Column'), + '/table/structure/change', + ['change_column' => 1, 'db' => null, 'table' => null, 'field' => null], + ); $this->links = [ 'text' => [ 'route' => '/table/structure/change', 'params' => ['change_column' => 1, 'db' => null, 'table' => null, 'field' => null], ], - 'icon' => [ - 'route' => '/table/structure/change', - 'params' => ['change_column' => 1, 'db' => null, 'table' => null, 'field' => null], - ], 'title' => __('Structure'), ]; $this->urlParamName = 'field'; diff --git a/src/Navigation/Nodes/NodeColumnContainer.php b/src/Navigation/Nodes/NodeColumnContainer.php index 78405bd6a2..ee552066a4 100644 --- a/src/Navigation/Nodes/NodeColumnContainer.php +++ b/src/Navigation/Nodes/NodeColumnContainer.php @@ -22,25 +22,25 @@ class NodeColumnContainer extends Node { parent::__construct($config, __('Columns'), NodeType::Container); - $this->icon = ['image' => 'pause', 'title' => __('Columns')]; + $this->icon = new Icon('pause', __('Columns'), '/table/structure', ['db' => null, 'table' => null]); $this->links = [ 'text' => ['route' => '/table/structure', 'params' => ['db' => null, 'table' => null]], - 'icon' => ['route' => '/table/structure', 'params' => ['db' => null, 'table' => null]], ]; $this->realName = 'columns'; $newLabel = _pgettext('Create new column', 'New'); $new = $this->getInstanceForNewNode($newLabel, 'new_column italics'); - $new->icon = ['image' => 'b_column_add', 'title' => $newLabel]; + $new->icon = new Icon( + 'b_column_add', + $newLabel, + '/table/add-field', + ['field_where' => 'last', 'after_field' => '', 'db' => null, 'table' => null], + ); $new->links = [ 'text' => [ 'route' => '/table/add-field', 'params' => ['field_where' => 'last', 'after_field' => '', 'db' => null, 'table' => null], ], - 'icon' => [ - 'route' => '/table/add-field', - 'params' => ['field_where' => 'last', 'after_field' => '', 'db' => null, 'table' => null], - ], ]; $this->addChild($new); } diff --git a/src/Navigation/Nodes/NodeDatabase.php b/src/Navigation/Nodes/NodeDatabase.php index 61794408e5..223dbcbf40 100644 --- a/src/Navigation/Nodes/NodeDatabase.php +++ b/src/Navigation/Nodes/NodeDatabase.php @@ -48,14 +48,18 @@ class NodeDatabase extends Node { parent::__construct($config, $name); - $this->icon = ['image' => 's_db', 'title' => __('Database operations')]; + $this->icon = new Icon( + 's_db', + __('Database operations'), + '/database/operations', + ['db' => null], + ); $this->links = [ 'text' => [ 'route' => $this->config->settings['DefaultTabDatabase'], 'params' => ['db' => null], ], - 'icon' => ['route' => '/database/operations', 'params' => ['db' => null]], 'title' => __('Structure'), ]; diff --git a/src/Navigation/Nodes/NodeDatabaseContainer.php b/src/Navigation/Nodes/NodeDatabaseContainer.php index 972ecac65d..8d4ec730a5 100644 --- a/src/Navigation/Nodes/NodeDatabaseContainer.php +++ b/src/Navigation/Nodes/NodeDatabaseContainer.php @@ -45,10 +45,9 @@ class NodeDatabaseContainer extends Node $newLabel = _pgettext('Create new database', 'New'); $new = $this->getInstanceForNewNode($newLabel, 'new_database italics'); - $new->icon = ['image' => 'b_newdb', 'title' => $newLabel]; + $new->icon = new Icon('b_newdb', $newLabel, '/server/databases'); $new->links = [ 'text' => ['route' => '/server/databases', 'params' => []], - 'icon' => ['route' => '/server/databases', 'params' => []], ]; $this->addChild($new); } diff --git a/src/Navigation/Nodes/NodeEvent.php b/src/Navigation/Nodes/NodeEvent.php index bc117735df..63b1f9ea4a 100644 --- a/src/Navigation/Nodes/NodeEvent.php +++ b/src/Navigation/Nodes/NodeEvent.php @@ -21,16 +21,17 @@ class NodeEvent extends NodeDatabaseChild { parent::__construct($config, $name); - $this->icon = ['image' => 'b_events', 'title' => __('Event')]; + $this->icon = new Icon( + 'b_events', + __('Event'), + '/database/events', + ['edit_item' => 1, 'db' => null, 'item_name' => null], + ); $this->links = [ 'text' => [ 'route' => '/database/events', 'params' => ['edit_item' => 1, 'db' => null, 'item_name' => null], ], - 'icon' => [ - 'route' => '/database/events', - 'params' => ['export_item' => 1, 'db' => null, 'item_name' => null], - ], ]; $this->classes = 'event'; $this->urlParamName = 'item_name'; diff --git a/src/Navigation/Nodes/NodeEventContainer.php b/src/Navigation/Nodes/NodeEventContainer.php index 5aaeefa316..b67495399e 100644 --- a/src/Navigation/Nodes/NodeEventContainer.php +++ b/src/Navigation/Nodes/NodeEventContainer.php @@ -21,19 +21,17 @@ class NodeEventContainer extends NodeDatabaseChildContainer { parent::__construct($config, __('Events')); - $this->icon = ['image' => 'b_events', 'title' => __('Events')]; + $this->icon = new Icon('b_events', __('Events'), '/database/events', ['db' => null]); $this->links = [ 'text' => ['route' => '/database/events', 'params' => ['db' => null]], - 'icon' => ['route' => '/database/events', 'params' => ['db' => null]], ]; $this->realName = 'events'; $newLabel = _pgettext('Create new event', 'New'); $new = $this->getInstanceForNewNode($newLabel, 'new_event italics'); - $new->icon = ['image' => 'b_event_add', 'title' => $newLabel]; + $new->icon = new Icon('b_event_add', $newLabel, '/database/events', ['add_item' => 1, 'db' => null]); $new->links = [ 'text' => ['route' => '/database/events', 'params' => ['add_item' => 1, 'db' => null]], - 'icon' => ['route' => '/database/events', 'params' => ['add_item' => 1, 'db' => null]], ]; $this->addChild($new); } diff --git a/src/Navigation/Nodes/NodeFunction.php b/src/Navigation/Nodes/NodeFunction.php index b4bab7aabe..689d95e2c2 100644 --- a/src/Navigation/Nodes/NodeFunction.php +++ b/src/Navigation/Nodes/NodeFunction.php @@ -21,16 +21,17 @@ class NodeFunction extends NodeDatabaseChild { parent::__construct($config, $name); - $this->icon = ['image' => 'b_routines', 'title' => __('Function')]; + $this->icon = new Icon( + 'b_routines', + __('Function'), + '/database/routines', + ['item_type' => 'FUNCTION', 'execute_dialog' => 1, 'db' => null, 'item_name' => null], + ); $this->links = [ 'text' => [ 'route' => '/database/routines', 'params' => ['item_type' => 'FUNCTION', 'edit_item' => 1, 'db' => null, 'item_name' => null], ], - 'icon' => [ - 'route' => '/database/routines', - 'params' => ['item_type' => 'FUNCTION', 'execute_dialog' => 1, 'db' => null, 'item_name' => null], - ], ]; $this->classes = 'function'; $this->urlParamName = 'item_name'; diff --git a/src/Navigation/Nodes/NodeFunctionContainer.php b/src/Navigation/Nodes/NodeFunctionContainer.php index f5cf09efbc..ebb1bb4c51 100644 --- a/src/Navigation/Nodes/NodeFunctionContainer.php +++ b/src/Navigation/Nodes/NodeFunctionContainer.php @@ -21,25 +21,30 @@ class NodeFunctionContainer extends NodeDatabaseChildContainer { parent::__construct($config, __('Functions')); - $this->icon = ['image' => 'b_routines', 'title' => __('Functions')]; + $this->icon = new Icon( + 'b_routines', + __('Functions'), + '/database/routines', + ['type' => 'FUNCTION', 'db' => null], + ); $this->links = [ 'text' => ['route' => '/database/routines', 'params' => ['type' => 'FUNCTION', 'db' => null]], - 'icon' => ['route' => '/database/routines', 'params' => ['type' => 'FUNCTION', 'db' => null]], ]; $this->realName = 'functions'; $newLabel = _pgettext('Create new function', 'New'); $new = $this->getInstanceForNewNode($newLabel, 'new_function italics'); - $new->icon = ['image' => 'b_routine_add', 'title' => $newLabel]; + $new->icon = new Icon( + 'b_routine_add', + $newLabel, + '/database/routines', + ['item_type' => 'FUNCTION', 'add_item' => 1, 'db' => null], + ); $new->links = [ 'text' => [ 'route' => '/database/routines', 'params' => ['item_type' => 'FUNCTION', 'add_item' => 1, 'db' => null], ], - 'icon' => [ - 'route' => '/database/routines', - 'params' => ['item_type' => 'FUNCTION', 'add_item' => 1, 'db' => null], - ], ]; $this->addChild($new); } diff --git a/src/Navigation/Nodes/NodeIndex.php b/src/Navigation/Nodes/NodeIndex.php index afd83529b1..e26916083d 100644 --- a/src/Navigation/Nodes/NodeIndex.php +++ b/src/Navigation/Nodes/NodeIndex.php @@ -21,10 +21,14 @@ class NodeIndex extends Node { parent::__construct($config, $name); - $this->icon = ['image' => 'b_index', 'title' => __('Index')]; + $this->icon = new Icon( + 'b_index', + __('Index'), + '/table/indexes', + ['db' => null, 'table' => null, 'index' => null], + ); $this->links = [ 'text' => ['route' => '/table/indexes', 'params' => ['db' => null, 'table' => null, 'index' => null]], - 'icon' => ['route' => '/table/indexes', 'params' => ['db' => null, 'table' => null, 'index' => null]], ]; $this->classes = 'index'; $this->urlParamName = 'index'; diff --git a/src/Navigation/Nodes/NodeIndexContainer.php b/src/Navigation/Nodes/NodeIndexContainer.php index 82d306716f..775cd6aa9f 100644 --- a/src/Navigation/Nodes/NodeIndexContainer.php +++ b/src/Navigation/Nodes/NodeIndexContainer.php @@ -22,25 +22,25 @@ class NodeIndexContainer extends Node { parent::__construct($config, __('Indexes'), NodeType::Container); - $this->icon = ['image' => 'b_index', 'title' => __('Indexes')]; + $this->icon = new Icon('b_index', __('Indexes'), '/table/structure', ['db' => null, 'table' => null]); $this->links = [ 'text' => ['route' => '/table/structure', 'params' => ['db' => null, 'table' => null]], - 'icon' => ['route' => '/table/structure', 'params' => ['db' => null, 'table' => null]], ]; $this->realName = 'indexes'; $newLabel = _pgettext('Create new index', 'New'); $new = $this->getInstanceForNewNode($newLabel, 'new_index italics'); - $new->icon = ['image' => 'b_index_add', 'title' => $newLabel]; + $new->icon = new Icon( + 'b_index_add', + $newLabel, + '/table/indexes', + ['create_index' => 1, 'added_fields' => 2, 'db' => null, 'table' => null], + ); $new->links = [ 'text' => [ 'route' => '/table/indexes', 'params' => ['create_index' => 1, 'added_fields' => 2, 'db' => null, 'table' => null], ], - 'icon' => [ - 'route' => '/table/indexes', - 'params' => ['create_index' => 1, 'added_fields' => 2, 'db' => null, 'table' => null], - ], ]; $this->addChild($new); } diff --git a/src/Navigation/Nodes/NodeProcedure.php b/src/Navigation/Nodes/NodeProcedure.php index 5d6f254807..25a2d97061 100644 --- a/src/Navigation/Nodes/NodeProcedure.php +++ b/src/Navigation/Nodes/NodeProcedure.php @@ -21,16 +21,17 @@ class NodeProcedure extends NodeDatabaseChild { parent::__construct($config, $name); - $this->icon = ['image' => 'b_routines', 'title' => __('Procedure')]; + $this->icon = new Icon( + 'b_routines', + __('Procedure'), + '/database/routines', + ['item_type' => 'PROCEDURE', 'execute_dialog' => 1, 'db' => null, 'item_name' => null], + ); $this->links = [ 'text' => [ 'route' => '/database/routines', 'params' => ['item_type' => 'PROCEDURE', 'edit_item' => 1, 'db' => null, 'item_name' => null], ], - 'icon' => [ - 'route' => '/database/routines', - 'params' => ['item_type' => 'PROCEDURE', 'execute_dialog' => 1, 'db' => null, 'item_name' => null], - ], ]; $this->classes = 'procedure'; $this->urlParamName = 'item_name'; diff --git a/src/Navigation/Nodes/NodeProcedureContainer.php b/src/Navigation/Nodes/NodeProcedureContainer.php index 8f40385e52..667f32dcb3 100644 --- a/src/Navigation/Nodes/NodeProcedureContainer.php +++ b/src/Navigation/Nodes/NodeProcedureContainer.php @@ -21,19 +21,27 @@ class NodeProcedureContainer extends NodeDatabaseChildContainer { parent::__construct($config, __('Procedures')); - $this->icon = ['image' => 'b_routines', 'title' => __('Procedures')]; + $this->icon = new Icon( + 'b_routines', + __('Procedures'), + '/database/routines', + ['type' => 'PROCEDURE', 'db' => null], + ); $this->links = [ 'text' => ['route' => '/database/routines', 'params' => ['type' => 'PROCEDURE', 'db' => null]], - 'icon' => ['route' => '/database/routines', 'params' => ['type' => 'PROCEDURE', 'db' => null]], ]; $this->realName = 'procedures'; $newLabel = _pgettext('Create new procedure', 'New'); $new = $this->getInstanceForNewNode($newLabel, 'new_procedure italics'); - $new->icon = ['image' => 'b_routine_add', 'title' => $newLabel]; + $new->icon = new Icon( + 'b_routine_add', + $newLabel, + '/database/routines', + ['add_item' => 1, 'db' => null], + ); $new->links = [ 'text' => ['route' => '/database/routines', 'params' => ['add_item' => 1, 'db' => null]], - 'icon' => ['route' => '/database/routines', 'params' => ['add_item' => 1, 'db' => null]], ]; $this->addChild($new); } diff --git a/src/Navigation/Nodes/NodeTable.php b/src/Navigation/Nodes/NodeTable.php index 6341de4663..4d4b114541 100644 --- a/src/Navigation/Nodes/NodeTable.php +++ b/src/Navigation/Nodes/NodeTable.php @@ -23,23 +23,26 @@ class NodeTable extends NodeDatabaseChild { /** * For the second IMG tag, used when rendering the node. - * - * @var array|null - * @psalm-var array{image: string, title: string}|null */ - public array|null $secondIcon = null; + public Icon|null $secondIcon = null; /** @param string $name An identifier for the new node */ public function __construct(Config $config, string $name) { parent::__construct($config, $name); - $icon = $this->addIcon($this->config->settings['NavigationTreeDefaultTabTable']); + $icon = $this->addIcon( + $this->config->settings['NavigationTreeDefaultTabTable'], + ['db' => null, 'table' => null], + ); if ($icon !== null) { $this->icon = $icon; } - $this->secondIcon = $this->addIcon($this->config->settings['NavigationTreeDefaultTabTable2']); + $this->secondIcon = $this->addIcon( + $this->config->settings['NavigationTreeDefaultTabTable2'], + ['db' => null, 'table' => null], + ); $this->title = Util::getTitleForTarget($this->config->settings['DefaultTabTable']); $this->links = [ @@ -47,14 +50,6 @@ class NodeTable extends NodeDatabaseChild 'route' => $this->config->settings['DefaultTabTable'], 'params' => ['pos' => 0, 'db' => null, 'table' => null], ], - 'icon' => [ - 'route' => $this->config->settings['NavigationTreeDefaultTabTable'], - 'params' => ['db' => null, 'table' => null], - ], - 'second_icon' => [ - 'route' => $this->config->settings['NavigationTreeDefaultTabTable2'], - 'params' => ['db' => null, 'table' => null], - ], 'title' => $this->title, ]; $this->classes = 'nav_node_table'; @@ -267,18 +262,17 @@ class NodeTable extends NodeDatabaseChild /** * Add an icon to navigation tree * - * @param '/table/sql'|'/table/search'|'/table/change'|'/sql'|'/table/structure'|'' $page Page name to redirect - * - * @return array{image: string, title: string}|null + * @param '/table/sql'|'/table/search'|'/table/change'|'/sql'|'/table/structure'|'' $page Page name to redirect + * @param array $params */ - private function addIcon(string $page): array|null + private function addIcon(string $page, array $params): Icon|null { return match ($page) { - '/table/structure' => ['image' => 'b_props', 'title' => __('Structure')], - '/table/search' => ['image' => 'b_search', 'title' => __('Search')], - '/table/change' => ['image' => 'b_insrow', 'title' => __('Insert')], - '/table/sql' => ['image' => 'b_sql', 'title' => __('SQL')], - '/sql' => ['image' => 'b_browse', 'title' => __('Browse')], + '/table/structure' => new Icon('b_props', __('Structure'), $page, $params), + '/table/search' => new Icon('b_search', __('Search'), $page, $params), + '/table/change' => new Icon('b_insrow', __('Insert'), $page, $params), + '/table/sql' => new Icon('b_sql', __('SQL'), $page, $params), + '/sql' => new Icon('b_browse', __('Browse'), $page, $params), default => null, }; } diff --git a/src/Navigation/Nodes/NodeTableContainer.php b/src/Navigation/Nodes/NodeTableContainer.php index dd9b8ea249..b8587e6e3e 100644 --- a/src/Navigation/Nodes/NodeTableContainer.php +++ b/src/Navigation/Nodes/NodeTableContainer.php @@ -21,20 +21,18 @@ class NodeTableContainer extends NodeDatabaseChildContainer { parent::__construct($config, __('Tables')); - $this->icon = ['image' => 'b_browse', 'title' => __('Tables')]; + $this->icon = new Icon('b_browse', __('Tables'), '/database/structure', ['tbl_type' => 'table', 'db' => null]); $this->links = [ 'text' => ['route' => '/database/structure', 'params' => ['tbl_type' => 'table', 'db' => null]], - 'icon' => ['route' => '/database/structure', 'params' => ['tbl_type' => 'table', 'db' => null]], ]; $this->realName = 'tables'; $this->classes = 'tableContainer subContainer'; $newLabel = _pgettext('Create new table', 'New'); $new = $this->getInstanceForNewNode($newLabel, 'new_table italics'); - $new->icon = ['image' => 'b_table_add', 'title' => $newLabel]; + $new->icon = new Icon('b_table_add', $newLabel, '/table/create', ['db' => null]); $new->links = [ 'text' => ['route' => '/table/create', 'params' => ['db' => null]], - 'icon' => ['route' => '/table/create', 'params' => ['db' => null]], ]; $this->addChild($new); } diff --git a/src/Navigation/Nodes/NodeTrigger.php b/src/Navigation/Nodes/NodeTrigger.php index b91ef5458a..1d79af2bfc 100644 --- a/src/Navigation/Nodes/NodeTrigger.php +++ b/src/Navigation/Nodes/NodeTrigger.php @@ -21,16 +21,17 @@ class NodeTrigger extends Node { parent::__construct($config, $name); - $this->icon = ['image' => 'b_triggers', 'title' => __('Trigger')]; + $this->icon = new Icon( + 'b_triggers', + __('Trigger'), + '/triggers', + ['export_item' => 1, 'db' => null, 'item_name' => null], + ); $this->links = [ 'text' => [ 'route' => '/triggers', 'params' => ['edit_item' => 1, 'db' => null, 'item_name' => null], ], - 'icon' => [ - 'route' => '/triggers', - 'params' => ['export_item' => 1, 'db' => null, 'item_name' => null], - ], ]; $this->classes = 'trigger'; $this->urlParamName = 'item_name'; diff --git a/src/Navigation/Nodes/NodeTriggerContainer.php b/src/Navigation/Nodes/NodeTriggerContainer.php index 953c034615..d94825a11e 100644 --- a/src/Navigation/Nodes/NodeTriggerContainer.php +++ b/src/Navigation/Nodes/NodeTriggerContainer.php @@ -22,19 +22,17 @@ class NodeTriggerContainer extends Node { parent::__construct($config, __('Triggers'), NodeType::Container); - $this->icon = ['image' => 'b_triggers', 'title' => __('Triggers')]; + $this->icon = new Icon('b_triggers', __('Triggers'), '/triggers', ['db' => null, 'table' => null]); $this->links = [ 'text' => ['route' => '/triggers', 'params' => ['db' => null, 'table' => null]], - 'icon' => ['route' => '/triggers', 'params' => ['db' => null, 'table' => null]], ]; $this->realName = 'triggers'; $newLabel = _pgettext('Create new trigger', 'New'); $new = $this->getInstanceForNewNode($newLabel, 'new_trigger italics'); - $new->icon = ['image' => 'b_trigger_add', 'title' => $newLabel]; + $new->icon = new Icon('b_trigger_add', $newLabel, '/triggers', ['add_item' => 1, 'db' => null]); $new->links = [ 'text' => ['route' => '/triggers', 'params' => ['add_item' => 1, 'db' => null]], - 'icon' => ['route' => '/triggers', 'params' => ['add_item' => 1, 'db' => null]], ]; $this->addChild($new); } diff --git a/src/Navigation/Nodes/NodeView.php b/src/Navigation/Nodes/NodeView.php index 001ba53239..6186861f3b 100644 --- a/src/Navigation/Nodes/NodeView.php +++ b/src/Navigation/Nodes/NodeView.php @@ -21,10 +21,9 @@ class NodeView extends NodeDatabaseChild { parent::__construct($config, $name); - $this->icon = ['image' => 'b_props', 'title' => __('View')]; + $this->icon = new Icon('b_props', __('View'), '/table/structure', ['db' => null, 'table' => null]); $this->links = [ 'text' => ['route' => '/sql', 'params' => ['pos' => 0, 'db' => null, 'table' => null]], - 'icon' => ['route' => '/table/structure', 'params' => ['db' => null, 'table' => null]], ]; $this->classes = 'view'; $this->urlParamName = 'table'; diff --git a/src/Navigation/Nodes/NodeViewContainer.php b/src/Navigation/Nodes/NodeViewContainer.php index 60fdd5a37e..0c15cce278 100644 --- a/src/Navigation/Nodes/NodeViewContainer.php +++ b/src/Navigation/Nodes/NodeViewContainer.php @@ -21,20 +21,18 @@ class NodeViewContainer extends NodeDatabaseChildContainer { parent::__construct($config, __('Views')); - $this->icon = ['image' => 'b_views', 'title' => __('Views')]; + $this->icon = new Icon('b_views', __('Views'), '/database/structure', ['tbl_type' => 'view', 'db' => null]); $this->links = [ 'text' => ['route' => '/database/structure', 'params' => ['tbl_type' => 'view', 'db' => null]], - 'icon' => ['route' => '/database/structure', 'params' => ['tbl_type' => 'view', 'db' => null]], ]; $this->classes = 'viewContainer subContainer'; $this->realName = 'views'; $newLabel = _pgettext('Create new view', 'New'); $new = $this->getInstanceForNewNode($newLabel, 'new_view italics'); - $new->icon = ['image' => 'b_view_add', 'title' => $newLabel]; + $new->icon = new Icon('b_view_add', $newLabel, '/view/create', ['db' => null]); $new->links = [ 'text' => ['route' => '/view/create', 'params' => ['db' => null]], - 'icon' => ['route' => '/view/create', 'params' => ['db' => null]], ]; $this->addChild($new); } diff --git a/tests/unit/Navigation/Nodes/NodeColumnContainerTest.php b/tests/unit/Navigation/Nodes/NodeColumnContainerTest.php index 9e2105f3a4..9bf730efea 100644 --- a/tests/unit/Navigation/Nodes/NodeColumnContainerTest.php +++ b/tests/unit/Navigation/Nodes/NodeColumnContainerTest.php @@ -19,11 +19,13 @@ final class NodeColumnContainerTest extends AbstractTestCase self::assertSame('Columns', $nodeColumnContainer->name); self::assertSame(NodeType::Container, $nodeColumnContainer->type); self::assertFalse($nodeColumnContainer->isGroup); - self::assertSame(['image' => 'pause', 'title' => 'Columns'], $nodeColumnContainer->icon); + self::assertSame('pause', $nodeColumnContainer->icon->image); + self::assertSame('Columns', $nodeColumnContainer->icon->title); + self::assertSame('/table/structure', $nodeColumnContainer->icon->route); + self::assertSame(['db' => null, 'table' => null], $nodeColumnContainer->icon->params); self::assertSame( [ 'text' => ['route' => '/table/structure', 'params' => ['db' => null, 'table' => null]], - 'icon' => ['route' => '/table/structure', 'params' => ['db' => null, 'table' => null]], ], $nodeColumnContainer->links, ); @@ -35,17 +37,19 @@ final class NodeColumnContainerTest extends AbstractTestCase self::assertSame('New', $newNode->title); self::assertTrue($newNode->isNew); self::assertSame('new_column italics', $newNode->classes); - self::assertSame(['image' => 'b_column_add', 'title' => 'New'], $newNode->icon); + self::assertSame('b_column_add', $newNode->icon->image); + self::assertSame('/table/add-field', $newNode->icon->route); + self::assertSame('New', $newNode->icon->title); + self::assertSame( + ['field_where' => 'last', 'after_field' => '', 'db' => null, 'table' => null], + $newNode->icon->params, + ); self::assertSame( [ 'text' => [ 'route' => '/table/add-field', 'params' => ['field_where' => 'last', 'after_field' => '', 'db' => null, 'table' => null], ], - 'icon' => [ - 'route' => '/table/add-field', - 'params' => ['field_where' => 'last', 'after_field' => '', 'db' => null, 'table' => null], - ], ], $newNode->links, ); diff --git a/tests/unit/Navigation/Nodes/NodeColumnTest.php b/tests/unit/Navigation/Nodes/NodeColumnTest.php index cf62543ae7..de7a4d8378 100644 --- a/tests/unit/Navigation/Nodes/NodeColumnTest.php +++ b/tests/unit/Navigation/Nodes/NodeColumnTest.php @@ -26,17 +26,19 @@ final class NodeColumnTest extends AbstractTestCase self::assertSame(NodeType::Object, $nodeColumn->type); self::assertFalse($nodeColumn->isGroup); self::assertSame('actor_id (PRI, smallint)', $nodeColumn->displayName); - self::assertSame(['image' => 'b_primary', 'title' => 'Column'], $nodeColumn->icon); + self::assertSame('b_primary', $nodeColumn->icon->image); + self::assertSame('Column', $nodeColumn->icon->title); + self::assertSame('/table/structure/change', $nodeColumn->icon->route); + self::assertSame( + ['change_column' => 1, 'db' => null, 'table' => null, 'field' => null], + $nodeColumn->icon->params, + ); self::assertSame( [ 'text' => [ 'route' => '/table/structure/change', 'params' => ['change_column' => 1, 'db' => null, 'table' => null, 'field' => null], ], - 'icon' => [ - 'route' => '/table/structure/change', - 'params' => ['change_column' => 1, 'db' => null, 'table' => null, 'field' => null], - ], 'title' => 'Structure', ], $nodeColumn->links, @@ -54,7 +56,8 @@ final class NodeColumnTest extends AbstractTestCase 'nullable' => '', ]); self::assertSame('last_update (timestamp, curren...)', $nodeColumn->displayName); - self::assertSame(['image' => 'pause', 'title' => 'Column'], $nodeColumn->icon); + self::assertSame('pause', $nodeColumn->icon->image); + self::assertSame('Column', $nodeColumn->icon->title); } public function testColumnNodeWithTruncatedDefaultValue2(): void @@ -67,7 +70,8 @@ final class NodeColumnTest extends AbstractTestCase 'nullable' => 'nullable', ]); self::assertSame('email (UNI, varchar, defaul..., nullable)', $nodeColumn->displayName); - self::assertSame(['image' => 'bd_primary', 'title' => 'Column'], $nodeColumn->icon); + self::assertSame('bd_primary', $nodeColumn->icon->image); + self::assertSame('Column', $nodeColumn->icon->title); } public function testColumnNodeWithoutTruncatedDefaultValue(): void @@ -80,6 +84,7 @@ final class NodeColumnTest extends AbstractTestCase 'nullable' => '', ]); self::assertSame('email (varchar, column)', $nodeColumn->displayName); - self::assertSame(['image' => 'pause', 'title' => 'Column'], $nodeColumn->icon); + self::assertSame('pause', $nodeColumn->icon->image); + self::assertSame('Column', $nodeColumn->icon->title); } } diff --git a/tests/unit/Navigation/Nodes/NodeDatabaseTest.php b/tests/unit/Navigation/Nodes/NodeDatabaseTest.php index 34fb59bee2..d87d9c2678 100644 --- a/tests/unit/Navigation/Nodes/NodeDatabaseTest.php +++ b/tests/unit/Navigation/Nodes/NodeDatabaseTest.php @@ -24,11 +24,12 @@ class NodeDatabaseTest extends AbstractTestCase self::assertSame( [ 'text' => ['route' => '/database/structure', 'params' => ['db' => null]], - 'icon' => ['route' => '/database/operations', 'params' => ['db' => null]], 'title' => 'Structure', ], $parent->links, ); + self::assertSame('/database/operations', $parent->icon->route); + self::assertSame(['db' => null], $parent->icon->params); self::assertStringContainsString('database', $parent->classes); } diff --git a/tests/unit/Navigation/Nodes/NodeEventContainerTest.php b/tests/unit/Navigation/Nodes/NodeEventContainerTest.php index ba3dffdf9f..735455109f 100644 --- a/tests/unit/Navigation/Nodes/NodeEventContainerTest.php +++ b/tests/unit/Navigation/Nodes/NodeEventContainerTest.php @@ -21,10 +21,11 @@ class NodeEventContainerTest extends AbstractTestCase self::assertSame( [ 'text' => ['route' => '/database/events', 'params' => ['db' => null]], - 'icon' => ['route' => '/database/events', 'params' => ['db' => null]], ], $parent->links, ); + self::assertSame('/database/events', $parent->icon->route); + self::assertSame(['db' => null], $parent->icon->params); self::assertSame('events', $parent->realName); } } diff --git a/tests/unit/Navigation/Nodes/NodeEventTest.php b/tests/unit/Navigation/Nodes/NodeEventTest.php index c21ebd0c49..2c2e5ea498 100644 --- a/tests/unit/Navigation/Nodes/NodeEventTest.php +++ b/tests/unit/Navigation/Nodes/NodeEventTest.php @@ -24,12 +24,10 @@ class NodeEventTest extends AbstractTestCase 'route' => '/database/events', 'params' => ['edit_item' => 1, 'db' => null, 'item_name' => null], ], - 'icon' => [ - 'route' => '/database/events', - 'params' => ['export_item' => 1, 'db' => null, 'item_name' => null], - ], ], $parent->links, ); + self::assertSame('/database/events', $parent->icon->route); + self::assertSame(['edit_item' => 1, 'db' => null, 'item_name' => null], $parent->icon->params); } } diff --git a/tests/unit/Navigation/Nodes/NodeFunctionContainerTest.php b/tests/unit/Navigation/Nodes/NodeFunctionContainerTest.php index 784973b6e1..bbfffd8d2a 100644 --- a/tests/unit/Navigation/Nodes/NodeFunctionContainerTest.php +++ b/tests/unit/Navigation/Nodes/NodeFunctionContainerTest.php @@ -21,10 +21,11 @@ class NodeFunctionContainerTest extends AbstractTestCase self::assertSame( [ 'text' => ['route' => '/database/routines', 'params' => ['type' => 'FUNCTION', 'db' => null]], - 'icon' => ['route' => '/database/routines', 'params' => ['type' => 'FUNCTION', 'db' => null]], ], $parent->links, ); + self::assertSame('/database/routines', $parent->icon->route); + self::assertSame(['type' => 'FUNCTION', 'db' => null], $parent->icon->params); self::assertSame('functions', $parent->realName); } } diff --git a/tests/unit/Navigation/Nodes/NodeFunctionTest.php b/tests/unit/Navigation/Nodes/NodeFunctionTest.php index fbf999ce30..6ab67c057c 100644 --- a/tests/unit/Navigation/Nodes/NodeFunctionTest.php +++ b/tests/unit/Navigation/Nodes/NodeFunctionTest.php @@ -24,12 +24,13 @@ class NodeFunctionTest extends AbstractTestCase 'route' => '/database/routines', 'params' => ['item_type' => 'FUNCTION', 'edit_item' => 1, 'db' => null, 'item_name' => null], ], - 'icon' => [ - 'route' => '/database/routines', - 'params' => ['item_type' => 'FUNCTION', 'execute_dialog' => 1, 'db' => null, 'item_name' => null], - ], ], $parent->links, ); + self::assertSame('/database/routines', $parent->icon->route); + self::assertSame( + ['item_type' => 'FUNCTION', 'execute_dialog' => 1, 'db' => null, 'item_name' => null], + $parent->icon->params, + ); } } diff --git a/tests/unit/Navigation/Nodes/NodeIndexContainerTest.php b/tests/unit/Navigation/Nodes/NodeIndexContainerTest.php index 76abe373a4..9aa55ae9fc 100644 --- a/tests/unit/Navigation/Nodes/NodeIndexContainerTest.php +++ b/tests/unit/Navigation/Nodes/NodeIndexContainerTest.php @@ -21,10 +21,11 @@ class NodeIndexContainerTest extends AbstractTestCase self::assertSame( [ 'text' => ['route' => '/table/structure', 'params' => ['db' => null, 'table' => null]], - 'icon' => ['route' => '/table/structure', 'params' => ['db' => null, 'table' => null]], ], $parent->links, ); + self::assertSame('/table/structure', $parent->icon->route); + self::assertSame(['db' => null, 'table' => null], $parent->icon->params); self::assertSame('indexes', $parent->realName); } } diff --git a/tests/unit/Navigation/Nodes/NodeIndexTest.php b/tests/unit/Navigation/Nodes/NodeIndexTest.php index 9de815551c..594094fbf8 100644 --- a/tests/unit/Navigation/Nodes/NodeIndexTest.php +++ b/tests/unit/Navigation/Nodes/NodeIndexTest.php @@ -21,9 +21,10 @@ class NodeIndexTest extends AbstractTestCase self::assertSame( [ 'text' => ['route' => '/table/indexes', 'params' => ['db' => null, 'table' => null, 'index' => null]], - 'icon' => ['route' => '/table/indexes', 'params' => ['db' => null, 'table' => null, 'index' => null]], ], $parent->links, ); + self::assertSame('/table/indexes', $parent->icon->route); + self::assertSame(['db' => null, 'table' => null, 'index' => null], $parent->icon->params); } } diff --git a/tests/unit/Navigation/Nodes/NodeProcedureContainerTest.php b/tests/unit/Navigation/Nodes/NodeProcedureContainerTest.php index e2f29f6aee..fe88b1d7b5 100644 --- a/tests/unit/Navigation/Nodes/NodeProcedureContainerTest.php +++ b/tests/unit/Navigation/Nodes/NodeProcedureContainerTest.php @@ -21,10 +21,11 @@ class NodeProcedureContainerTest extends AbstractTestCase self::assertSame( [ 'text' => ['route' => '/database/routines', 'params' => ['type' => 'PROCEDURE', 'db' => null]], - 'icon' => ['route' => '/database/routines', 'params' => ['type' => 'PROCEDURE', 'db' => null]], ], $parent->links, ); self::assertSame('procedures', $parent->realName); + self::assertSame('/database/routines', $parent->icon->route); + self::assertSame(['type' => 'PROCEDURE', 'db' => null], $parent->icon->params); } } diff --git a/tests/unit/Navigation/Nodes/NodeProcedureTest.php b/tests/unit/Navigation/Nodes/NodeProcedureTest.php index 9369fbb6e8..abd8047847 100644 --- a/tests/unit/Navigation/Nodes/NodeProcedureTest.php +++ b/tests/unit/Navigation/Nodes/NodeProcedureTest.php @@ -24,12 +24,13 @@ class NodeProcedureTest extends AbstractTestCase 'route' => '/database/routines', 'params' => ['item_type' => 'PROCEDURE', 'edit_item' => 1, 'db' => null, 'item_name' => null], ], - 'icon' => [ - 'route' => '/database/routines', - 'params' => ['item_type' => 'PROCEDURE', 'execute_dialog' => 1, 'db' => null, 'item_name' => null], - ], ], $parent->links, ); + self::assertSame('/database/routines', $parent->icon->route); + self::assertSame( + ['item_type' => 'PROCEDURE', 'execute_dialog' => 1, 'db' => null, 'item_name' => null], + $parent->icon->params, + ); } } diff --git a/tests/unit/Navigation/Nodes/NodeTableContainerTest.php b/tests/unit/Navigation/Nodes/NodeTableContainerTest.php index 22215c7cad..d143ef61fe 100644 --- a/tests/unit/Navigation/Nodes/NodeTableContainerTest.php +++ b/tests/unit/Navigation/Nodes/NodeTableContainerTest.php @@ -21,10 +21,11 @@ class NodeTableContainerTest extends AbstractTestCase self::assertSame( [ 'text' => ['route' => '/database/structure', 'params' => ['tbl_type' => 'table', 'db' => null]], - 'icon' => ['route' => '/database/structure', 'params' => ['tbl_type' => 'table', 'db' => null]], ], $parent->links, ); + self::assertSame('/database/structure', $parent->icon->route); + self::assertSame(['tbl_type' => 'table', 'db' => null], $parent->icon->params); self::assertSame('tables', $parent->realName); self::assertStringContainsString('tableContainer', $parent->classes); } diff --git a/tests/unit/Navigation/Nodes/NodeTableTest.php b/tests/unit/Navigation/Nodes/NodeTableTest.php index 54984bacc1..e7501e738d 100644 --- a/tests/unit/Navigation/Nodes/NodeTableTest.php +++ b/tests/unit/Navigation/Nodes/NodeTableTest.php @@ -26,12 +26,15 @@ class NodeTableTest extends AbstractTestCase self::assertSame( [ 'text' => ['route' => '/sql', 'params' => ['pos' => 0, 'db' => null, 'table' => null]], - 'icon' => ['route' => '/table/search', 'params' => ['db' => null, 'table' => null]], - 'second_icon' => ['route' => '/table/change', 'params' => ['db' => null, 'table' => null]], 'title' => 'Browse', ], $parent->links, ); + self::assertSame('/table/search', $parent->icon->route); + self::assertSame(['db' => null, 'table' => null], $parent->icon->params); + self::assertNotNull($parent->secondIcon); + self::assertSame('/table/change', $parent->secondIcon->route); + self::assertSame(['db' => null, 'table' => null], $parent->secondIcon->params); self::assertStringContainsString('table', $parent->classes); } @@ -46,8 +49,8 @@ class NodeTableTest extends AbstractTestCase $config = Config::getInstance(); $config->settings['NavigationTreeDefaultTabTable'] = $target; $node = new NodeTable($config, 'default'); - self::assertSame($imageName, $node->icon['image']); - self::assertSame($imageTitle, $node->icon['title']); + self::assertSame($imageName, $node->icon->image); + self::assertSame($imageTitle, $node->icon->title); } /** diff --git a/tests/unit/Navigation/Nodes/NodeTriggerContainerTest.php b/tests/unit/Navigation/Nodes/NodeTriggerContainerTest.php index 4c57e78f19..c7428cc6e5 100644 --- a/tests/unit/Navigation/Nodes/NodeTriggerContainerTest.php +++ b/tests/unit/Navigation/Nodes/NodeTriggerContainerTest.php @@ -21,10 +21,11 @@ class NodeTriggerContainerTest extends AbstractTestCase self::assertSame( [ 'text' => ['route' => '/triggers', 'params' => ['db' => null, 'table' => null]], - 'icon' => ['route' => '/triggers', 'params' => ['db' => null, 'table' => null]], ], $parent->links, ); + self::assertSame('/triggers', $parent->icon->route); + self::assertSame(['db' => null, 'table' => null], $parent->icon->params); self::assertSame('triggers', $parent->realName); } } diff --git a/tests/unit/Navigation/Nodes/NodeTriggerTest.php b/tests/unit/Navigation/Nodes/NodeTriggerTest.php index 07acc7c2de..d7780bf9b9 100644 --- a/tests/unit/Navigation/Nodes/NodeTriggerTest.php +++ b/tests/unit/Navigation/Nodes/NodeTriggerTest.php @@ -24,12 +24,13 @@ class NodeTriggerTest extends AbstractTestCase 'route' => '/triggers', 'params' => ['edit_item' => 1, 'db' => null, 'item_name' => null], ], - 'icon' => [ - 'route' => '/triggers', - 'params' => ['export_item' => 1, 'db' => null, 'item_name' => null], - ], ], $parent->links, ); + self::assertSame('/triggers', $parent->icon->route); + self::assertSame( + ['export_item' => 1, 'db' => null, 'item_name' => null], + $parent->icon->params, + ); } } diff --git a/tests/unit/Navigation/Nodes/NodeViewContainerTest.php b/tests/unit/Navigation/Nodes/NodeViewContainerTest.php index 207f3df81e..27a59ef536 100644 --- a/tests/unit/Navigation/Nodes/NodeViewContainerTest.php +++ b/tests/unit/Navigation/Nodes/NodeViewContainerTest.php @@ -21,10 +21,11 @@ class NodeViewContainerTest extends AbstractTestCase self::assertSame( [ 'text' => ['route' => '/database/structure', 'params' => ['tbl_type' => 'view', 'db' => null]], - 'icon' => ['route' => '/database/structure', 'params' => ['tbl_type' => 'view', 'db' => null]], ], $parent->links, ); + self::assertSame('/database/structure', $parent->icon->route); + self::assertSame(['tbl_type' => 'view', 'db' => null], $parent->icon->params); self::assertSame('views', $parent->realName); self::assertStringContainsString('viewContainer', $parent->classes); } diff --git a/tests/unit/Navigation/Nodes/NodeViewTest.php b/tests/unit/Navigation/Nodes/NodeViewTest.php index 05aecb91bc..14eec87c29 100644 --- a/tests/unit/Navigation/Nodes/NodeViewTest.php +++ b/tests/unit/Navigation/Nodes/NodeViewTest.php @@ -21,12 +21,13 @@ class NodeViewTest extends AbstractTestCase self::assertSame( [ 'text' => ['route' => '/sql', 'params' => ['pos' => 0, 'db' => null, 'table' => null]], - 'icon' => ['route' => '/table/structure', 'params' => ['db' => null, 'table' => null]], ], $parent->links, ); - self::assertSame('b_props', $parent->icon['image']); - self::assertSame('View', $parent->icon['title']); + self::assertSame('b_props', $parent->icon->image); + self::assertSame('View', $parent->icon->title); + self::assertSame('/table/structure', $parent->icon->route); + self::assertSame(['db' => null, 'table' => null], $parent->icon->params); self::assertStringContainsString('view', $parent->classes); } }