From 1a5d10e66dbe2b02be175b9935ae6abd534bca24 Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Fri, 13 Jun 2025 00:25:04 +0100 Subject: [PATCH 1/3] Create Nodes/Icon Signed-off-by: Kamil Tekiela --- resources/templates/navigation/tree/node.twig | 2 +- src/Navigation/NavigationTree.php | 41 +++++++------------ src/Navigation/Nodes/Icon.php | 28 +++++++++++++ src/Navigation/Nodes/Node.php | 10 ++--- src/Navigation/Nodes/NodeColumn.php | 11 ++--- src/Navigation/Nodes/NodeColumnContainer.php | 14 +++---- src/Navigation/Nodes/NodeDatabase.php | 8 +++- .../Nodes/NodeDatabaseContainer.php | 3 +- src/Navigation/Nodes/NodeEvent.php | 11 ++--- src/Navigation/Nodes/NodeEventContainer.php | 6 +-- src/Navigation/Nodes/NodeFunction.php | 11 ++--- .../Nodes/NodeFunctionContainer.php | 19 +++++---- src/Navigation/Nodes/NodeIndex.php | 8 +++- src/Navigation/Nodes/NodeIndexContainer.php | 14 +++---- src/Navigation/Nodes/NodeProcedure.php | 11 ++--- .../Nodes/NodeProcedureContainer.php | 16 ++++++-- src/Navigation/Nodes/NodeTable.php | 40 ++++++++---------- src/Navigation/Nodes/NodeTableContainer.php | 6 +-- src/Navigation/Nodes/NodeTrigger.php | 11 ++--- src/Navigation/Nodes/NodeTriggerContainer.php | 6 +-- src/Navigation/Nodes/NodeView.php | 3 +- src/Navigation/Nodes/NodeViewContainer.php | 6 +-- .../Nodes/NodeColumnContainerTest.php | 18 ++++---- .../unit/Navigation/Nodes/NodeColumnTest.php | 21 ++++++---- .../Navigation/Nodes/NodeDatabaseTest.php | 3 +- .../Nodes/NodeEventContainerTest.php | 3 +- tests/unit/Navigation/Nodes/NodeEventTest.php | 6 +-- .../Nodes/NodeFunctionContainerTest.php | 3 +- .../Navigation/Nodes/NodeFunctionTest.php | 9 ++-- .../Nodes/NodeIndexContainerTest.php | 3 +- tests/unit/Navigation/Nodes/NodeIndexTest.php | 3 +- .../Nodes/NodeProcedureContainerTest.php | 3 +- .../Navigation/Nodes/NodeProcedureTest.php | 9 ++-- .../Nodes/NodeTableContainerTest.php | 3 +- tests/unit/Navigation/Nodes/NodeTableTest.php | 11 +++-- .../Nodes/NodeTriggerContainerTest.php | 3 +- .../unit/Navigation/Nodes/NodeTriggerTest.php | 9 ++-- .../Nodes/NodeViewContainerTest.php | 3 +- tests/unit/Navigation/Nodes/NodeViewTest.php | 7 ++-- 39 files changed, 223 insertions(+), 179 deletions(-) create mode 100644 src/Navigation/Nodes/Icon.php 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); } } From dff3c7302228abf95e1747ac566929219b9ea134 Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Fri, 13 Jun 2025 02:09:10 +0100 Subject: [PATCH 2/3] Create Link class Signed-off-by: Kamil Tekiela --- src/Navigation/NavigationTree.php | 29 ++++++------------- src/Navigation/Nodes/Link.php | 24 +++++++++++++++ src/Navigation/Nodes/Node.php | 12 ++------ src/Navigation/Nodes/NodeColumn.php | 12 ++++---- src/Navigation/Nodes/NodeColumnContainer.php | 19 ++++++------ src/Navigation/Nodes/NodeDatabase.php | 12 ++++---- .../Nodes/NodeDatabaseContainer.php | 4 +-- src/Navigation/Nodes/NodeEvent.php | 11 ++++--- src/Navigation/Nodes/NodeEventContainer.php | 16 ++++++---- src/Navigation/Nodes/NodeFunction.php | 11 ++++--- .../Nodes/NodeFunctionContainer.php | 19 ++++++------ src/Navigation/Nodes/NodeIndex.php | 8 +++-- src/Navigation/Nodes/NodeIndexContainer.php | 19 ++++++------ src/Navigation/Nodes/NodeProcedure.php | 11 ++++--- .../Nodes/NodeProcedureContainer.php | 16 ++++++---- src/Navigation/Nodes/NodeTable.php | 12 ++++---- src/Navigation/Nodes/NodeTableContainer.php | 16 ++++++---- src/Navigation/Nodes/NodeTrigger.php | 11 ++++--- src/Navigation/Nodes/NodeTriggerContainer.php | 16 ++++++---- src/Navigation/Nodes/NodeView.php | 8 +++-- src/Navigation/Nodes/NodeViewContainer.php | 16 ++++++---- .../Nodes/NodeColumnContainerTest.php | 18 ++++-------- .../unit/Navigation/Nodes/NodeColumnTest.php | 12 +++----- .../Navigation/Nodes/NodeDatabaseTest.php | 10 ++----- .../Nodes/NodeEventContainerTest.php | 8 ++--- tests/unit/Navigation/Nodes/NodeEventTest.php | 11 ++----- .../Nodes/NodeFunctionContainerTest.php | 8 ++--- .../Navigation/Nodes/NodeFunctionTest.php | 10 ++----- .../Nodes/NodeIndexContainerTest.php | 8 ++--- tests/unit/Navigation/Nodes/NodeIndexTest.php | 8 ++--- .../Nodes/NodeProcedureContainerTest.php | 8 ++--- .../Navigation/Nodes/NodeProcedureTest.php | 10 ++----- .../Nodes/NodeTableContainerTest.php | 8 ++--- tests/unit/Navigation/Nodes/NodeTableTest.php | 10 ++----- .../Nodes/NodeTriggerContainerTest.php | 8 ++--- .../unit/Navigation/Nodes/NodeTriggerTest.php | 10 ++----- .../Nodes/NodeViewContainerTest.php | 8 ++--- tests/unit/Navigation/Nodes/NodeViewTest.php | 8 ++--- 38 files changed, 205 insertions(+), 260 deletions(-) create mode 100644 src/Navigation/Nodes/Link.php diff --git a/src/Navigation/NavigationTree.php b/src/Navigation/NavigationTree.php index df7230dae2..df027058b6 100644 --- a/src/Navigation/NavigationTree.php +++ b/src/Navigation/NavigationTree.php @@ -17,6 +17,7 @@ use PhpMyAdmin\Favorites\RecentFavoriteTables; use PhpMyAdmin\Favorites\TableType; use PhpMyAdmin\Html\Generator; use PhpMyAdmin\Navigation\Nodes\Icon; +use PhpMyAdmin\Navigation\Nodes\Link; use PhpMyAdmin\Navigation\Nodes\Node; use PhpMyAdmin\Navigation\Nodes\NodeColumn; use PhpMyAdmin\Navigation\Nodes\NodeColumnContainer; @@ -44,7 +45,6 @@ use PhpMyAdmin\UserPrivilegesFactory; use function __; use function _ngettext; -use function array_intersect_key; use function array_key_exists; use function array_key_last; use function array_keys; @@ -773,7 +773,7 @@ class NavigationTree $newChild->realName = $child->realName; $newChild->icon = $child->icon; - $newChild->links = $child->links; + $newChild->link = $child->link; $newChild->pos2 = $child->pos2; $newChild->pos3 = $child->pos3; foreach ($child->children as $elm) { @@ -812,12 +812,11 @@ class NavigationTree $groups[$key]->pos2 = $node->pos2; $groups[$key]->pos3 = $node->pos3; if ($node instanceof NodeTableContainer || $node instanceof NodeViewContainer) { - $groups[$key]->links = [ - 'text' => [ - 'route' => $node->links['text']['route'], - 'params' => array_merge($node->links['text']['params'], ['tbl_group' => $key]), - ], - ]; + $groups[$key]->link = new Link( + $groups[$key]->title, + $node->link->route, + array_merge($node->link->params, ['tbl_group' => $key]), + ); } foreach ($newChildren as $newChild) { @@ -1075,14 +1074,7 @@ class NavigationTree $iconLinks[] = $node->secondIcon->withDifferentParams($args); } - $textLink = [ - 'route' => $node->links['text']['route'], - 'params' => array_merge( - $node->links['text']['params'], - array_intersect_key($args, $node->links['text']['params']), - ), - 'title' => $node->links['title'] ?? $node->title, - ]; + $textLink = $node->link->withDifferentParams($args); } $controlButtons .= $node->getHtmlForControlButtons($this->relationParameters->navigationItemsHidingFeature); @@ -1167,11 +1159,8 @@ class NavigationTree } $paths = $node->getPaths(); - if (! isset($node->links['text'])) { - continue; - } - $title = $node->links['title'] ?? ''; + $title = $node->link->title; $options[] = [ 'title' => $title, 'name' => $node->realName, diff --git a/src/Navigation/Nodes/Link.php b/src/Navigation/Nodes/Link.php new file mode 100644 index 0000000000..1af25f9c37 --- /dev/null +++ b/src/Navigation/Nodes/Link.php @@ -0,0 +1,24 @@ + $params */ + public function __construct(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->title, $this->route, $params); + } +} diff --git a/src/Navigation/Nodes/Node.php b/src/Navigation/Nodes/Node.php index 2daa42ffe1..9933654750 100644 --- a/src/Navigation/Nodes/Node.php +++ b/src/Navigation/Nodes/Node.php @@ -74,16 +74,7 @@ class Node */ public Icon $icon; - /** - * An array of A tags, used when rendering the node. - * - * @var array - * @psalm-var array{ - * text: array{route: string, params: array}, - * title?: string - * } - */ - public array $links = ['text' => ['route' => '', 'params' => []]]; + public Link $link; /** @var string HTML title */ public string $title = ''; @@ -121,6 +112,7 @@ class Node ) { $this->realName = $name; $this->icon = new Icon('', '', ''); + $this->link = new Link('', '', []); } /** diff --git a/src/Navigation/Nodes/NodeColumn.php b/src/Navigation/Nodes/NodeColumn.php index 7afae81af8..521e8cb7d6 100644 --- a/src/Navigation/Nodes/NodeColumn.php +++ b/src/Navigation/Nodes/NodeColumn.php @@ -33,13 +33,11 @@ class NodeColumn extends Node '/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], - ], - 'title' => __('Structure'), - ]; + $this->link = new Link( + __('Structure'), + '/table/structure/change', + ['change_column' => 1, 'db' => null, 'table' => null, 'field' => null], + ); $this->urlParamName = 'field'; } diff --git a/src/Navigation/Nodes/NodeColumnContainer.php b/src/Navigation/Nodes/NodeColumnContainer.php index ee552066a4..1b1ff8acf9 100644 --- a/src/Navigation/Nodes/NodeColumnContainer.php +++ b/src/Navigation/Nodes/NodeColumnContainer.php @@ -23,9 +23,11 @@ class NodeColumnContainer extends Node parent::__construct($config, __('Columns'), NodeType::Container); $this->icon = new Icon('pause', __('Columns'), '/table/structure', ['db' => null, 'table' => null]); - $this->links = [ - 'text' => ['route' => '/table/structure', 'params' => ['db' => null, 'table' => null]], - ]; + $this->link = new Link( + $this->title, + '/table/structure', + ['db' => null, 'table' => null], + ); $this->realName = 'columns'; $newLabel = _pgettext('Create new column', 'New'); @@ -36,12 +38,11 @@ class NodeColumnContainer extends Node '/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], - ], - ]; + $new->link = new Link( + $new->title, + '/table/add-field', + ['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 223dbcbf40..0bbbf77587 100644 --- a/src/Navigation/Nodes/NodeDatabase.php +++ b/src/Navigation/Nodes/NodeDatabase.php @@ -55,13 +55,11 @@ class NodeDatabase extends Node ['db' => null], ); - $this->links = [ - 'text' => [ - 'route' => $this->config->settings['DefaultTabDatabase'], - 'params' => ['db' => null], - ], - 'title' => __('Structure'), - ]; + $this->link = new Link( + __('Structure'), + $this->config->settings['DefaultTabDatabase'], + ['db' => null], + ); $this->classes = 'database'; $this->urlParamName = 'db'; diff --git a/src/Navigation/Nodes/NodeDatabaseContainer.php b/src/Navigation/Nodes/NodeDatabaseContainer.php index 8d4ec730a5..ae3c6d08d5 100644 --- a/src/Navigation/Nodes/NodeDatabaseContainer.php +++ b/src/Navigation/Nodes/NodeDatabaseContainer.php @@ -46,9 +46,7 @@ class NodeDatabaseContainer extends Node $newLabel = _pgettext('Create new database', 'New'); $new = $this->getInstanceForNewNode($newLabel, 'new_database italics'); $new->icon = new Icon('b_newdb', $newLabel, '/server/databases'); - $new->links = [ - 'text' => ['route' => '/server/databases', 'params' => []], - ]; + $new->link = new Link($new->title, '/server/databases'); $this->addChild($new); } } diff --git a/src/Navigation/Nodes/NodeEvent.php b/src/Navigation/Nodes/NodeEvent.php index 63b1f9ea4a..6c033eb4b2 100644 --- a/src/Navigation/Nodes/NodeEvent.php +++ b/src/Navigation/Nodes/NodeEvent.php @@ -27,12 +27,11 @@ class NodeEvent extends NodeDatabaseChild '/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], - ], - ]; + $this->link = new Link( + $this->title, + '/database/events', + ['edit_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 b67495399e..e88b79a381 100644 --- a/src/Navigation/Nodes/NodeEventContainer.php +++ b/src/Navigation/Nodes/NodeEventContainer.php @@ -22,17 +22,21 @@ class NodeEventContainer extends NodeDatabaseChildContainer parent::__construct($config, __('Events')); $this->icon = new Icon('b_events', __('Events'), '/database/events', ['db' => null]); - $this->links = [ - 'text' => ['route' => '/database/events', 'params' => ['db' => null]], - ]; + $this->link = new Link( + $this->title, + '/database/events', + ['db' => null], + ); $this->realName = 'events'; $newLabel = _pgettext('Create new event', 'New'); $new = $this->getInstanceForNewNode($newLabel, 'new_event italics'); $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]], - ]; + $new->link = new Link( + $new->title, + '/database/events', + ['add_item' => 1, 'db' => null], + ); $this->addChild($new); } } diff --git a/src/Navigation/Nodes/NodeFunction.php b/src/Navigation/Nodes/NodeFunction.php index 689d95e2c2..11b48a82ea 100644 --- a/src/Navigation/Nodes/NodeFunction.php +++ b/src/Navigation/Nodes/NodeFunction.php @@ -27,12 +27,11 @@ class NodeFunction extends NodeDatabaseChild '/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], - ], - ]; + $this->link = new Link( + $this->title, + '/database/routines', + ['item_type' => 'FUNCTION', 'edit_item' => 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 ebb1bb4c51..7fd40013c7 100644 --- a/src/Navigation/Nodes/NodeFunctionContainer.php +++ b/src/Navigation/Nodes/NodeFunctionContainer.php @@ -27,9 +27,11 @@ class NodeFunctionContainer extends NodeDatabaseChildContainer '/database/routines', ['type' => 'FUNCTION', 'db' => null], ); - $this->links = [ - 'text' => ['route' => '/database/routines', 'params' => ['type' => 'FUNCTION', 'db' => null]], - ]; + $this->link = new Link( + $this->title, + '/database/routines', + ['type' => 'FUNCTION', 'db' => null], + ); $this->realName = 'functions'; $newLabel = _pgettext('Create new function', 'New'); @@ -40,12 +42,11 @@ class NodeFunctionContainer extends NodeDatabaseChildContainer '/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], - ], - ]; + $new->link = new Link( + $new->title, + '/database/routines', + ['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 e26916083d..d2f38f9feb 100644 --- a/src/Navigation/Nodes/NodeIndex.php +++ b/src/Navigation/Nodes/NodeIndex.php @@ -27,9 +27,11 @@ class NodeIndex extends Node '/table/indexes', ['db' => null, 'table' => null, 'index' => null], ); - $this->links = [ - 'text' => ['route' => '/table/indexes', 'params' => ['db' => null, 'table' => null, 'index' => null]], - ]; + $this->link = new Link( + $this->title, + '/table/indexes', + ['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 775cd6aa9f..f3eb33405f 100644 --- a/src/Navigation/Nodes/NodeIndexContainer.php +++ b/src/Navigation/Nodes/NodeIndexContainer.php @@ -23,9 +23,11 @@ class NodeIndexContainer extends Node parent::__construct($config, __('Indexes'), NodeType::Container); $this->icon = new Icon('b_index', __('Indexes'), '/table/structure', ['db' => null, 'table' => null]); - $this->links = [ - 'text' => ['route' => '/table/structure', 'params' => ['db' => null, 'table' => null]], - ]; + $this->link = new Link( + $this->title, + '/table/structure', + ['db' => null, 'table' => null], + ); $this->realName = 'indexes'; $newLabel = _pgettext('Create new index', 'New'); @@ -36,12 +38,11 @@ class NodeIndexContainer extends Node '/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], - ], - ]; + $new->link = new Link( + $new->title, + '/table/indexes', + ['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 25a2d97061..524fb3a986 100644 --- a/src/Navigation/Nodes/NodeProcedure.php +++ b/src/Navigation/Nodes/NodeProcedure.php @@ -27,12 +27,11 @@ class NodeProcedure extends NodeDatabaseChild '/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], - ], - ]; + $this->link = new Link( + $this->title, + '/database/routines', + ['item_type' => 'PROCEDURE', 'edit_item' => 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 667f32dcb3..178911582f 100644 --- a/src/Navigation/Nodes/NodeProcedureContainer.php +++ b/src/Navigation/Nodes/NodeProcedureContainer.php @@ -27,9 +27,11 @@ class NodeProcedureContainer extends NodeDatabaseChildContainer '/database/routines', ['type' => 'PROCEDURE', 'db' => null], ); - $this->links = [ - 'text' => ['route' => '/database/routines', 'params' => ['type' => 'PROCEDURE', 'db' => null]], - ]; + $this->link = new Link( + $this->title, + '/database/routines', + ['type' => 'PROCEDURE', 'db' => null], + ); $this->realName = 'procedures'; $newLabel = _pgettext('Create new procedure', 'New'); @@ -40,9 +42,11 @@ class NodeProcedureContainer extends NodeDatabaseChildContainer '/database/routines', ['add_item' => 1, 'db' => null], ); - $new->links = [ - 'text' => ['route' => '/database/routines', 'params' => ['add_item' => 1, 'db' => null]], - ]; + $new->link = new Link( + $new->title, + '/database/routines', + ['add_item' => 1, 'db' => null], + ); $this->addChild($new); } } diff --git a/src/Navigation/Nodes/NodeTable.php b/src/Navigation/Nodes/NodeTable.php index 4d4b114541..1a6a833e96 100644 --- a/src/Navigation/Nodes/NodeTable.php +++ b/src/Navigation/Nodes/NodeTable.php @@ -45,13 +45,11 @@ class NodeTable extends NodeDatabaseChild ); $this->title = Util::getTitleForTarget($this->config->settings['DefaultTabTable']); - $this->links = [ - 'text' => [ - 'route' => $this->config->settings['DefaultTabTable'], - 'params' => ['pos' => 0, 'db' => null, 'table' => null], - ], - 'title' => $this->title, - ]; + $this->link = new Link( + $this->title, + $this->config->settings['DefaultTabTable'], + ['pos' => 0, 'db' => null, 'table' => null], + ); $this->classes = 'nav_node_table'; $this->urlParamName = 'table'; } diff --git a/src/Navigation/Nodes/NodeTableContainer.php b/src/Navigation/Nodes/NodeTableContainer.php index b8587e6e3e..db2bdf7e4e 100644 --- a/src/Navigation/Nodes/NodeTableContainer.php +++ b/src/Navigation/Nodes/NodeTableContainer.php @@ -22,18 +22,22 @@ class NodeTableContainer extends NodeDatabaseChildContainer parent::__construct($config, __('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]], - ]; + $this->link = new Link( + $this->title, + '/database/structure', + ['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 = new Icon('b_table_add', $newLabel, '/table/create', ['db' => null]); - $new->links = [ - 'text' => ['route' => '/table/create', 'params' => ['db' => null]], - ]; + $new->link = new Link( + $new->title, + '/table/create', + ['db' => null], + ); $this->addChild($new); } } diff --git a/src/Navigation/Nodes/NodeTrigger.php b/src/Navigation/Nodes/NodeTrigger.php index 1d79af2bfc..114df09087 100644 --- a/src/Navigation/Nodes/NodeTrigger.php +++ b/src/Navigation/Nodes/NodeTrigger.php @@ -27,12 +27,11 @@ class NodeTrigger extends Node '/triggers', ['export_item' => 1, 'db' => null, 'item_name' => null], ); - $this->links = [ - 'text' => [ - 'route' => '/triggers', - 'params' => ['edit_item' => 1, 'db' => null, 'item_name' => null], - ], - ]; + $this->link = new Link( + $this->title, + '/triggers', + ['edit_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 d94825a11e..cdf3c7b74c 100644 --- a/src/Navigation/Nodes/NodeTriggerContainer.php +++ b/src/Navigation/Nodes/NodeTriggerContainer.php @@ -23,17 +23,21 @@ class NodeTriggerContainer extends Node parent::__construct($config, __('Triggers'), NodeType::Container); $this->icon = new Icon('b_triggers', __('Triggers'), '/triggers', ['db' => null, 'table' => null]); - $this->links = [ - 'text' => ['route' => '/triggers', 'params' => ['db' => null, 'table' => null]], - ]; + $this->link = new Link( + $this->title, + '/triggers', + ['db' => null, 'table' => null], + ); $this->realName = 'triggers'; $newLabel = _pgettext('Create new trigger', 'New'); $new = $this->getInstanceForNewNode($newLabel, 'new_trigger italics'); $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]], - ]; + $new->link = new Link( + $new->title, + '/triggers', + ['add_item' => 1, 'db' => null], + ); $this->addChild($new); } } diff --git a/src/Navigation/Nodes/NodeView.php b/src/Navigation/Nodes/NodeView.php index 6186861f3b..c42b62bf05 100644 --- a/src/Navigation/Nodes/NodeView.php +++ b/src/Navigation/Nodes/NodeView.php @@ -22,9 +22,11 @@ class NodeView extends NodeDatabaseChild parent::__construct($config, $name); $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]], - ]; + $this->link = new Link( + $this->title, + '/sql', + ['pos' => 0, '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 0c15cce278..969b8e7c07 100644 --- a/src/Navigation/Nodes/NodeViewContainer.php +++ b/src/Navigation/Nodes/NodeViewContainer.php @@ -22,18 +22,22 @@ class NodeViewContainer extends NodeDatabaseChildContainer parent::__construct($config, __('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]], - ]; + $this->link = new Link( + $this->title, + '/database/structure', + ['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 = new Icon('b_view_add', $newLabel, '/view/create', ['db' => null]); - $new->links = [ - 'text' => ['route' => '/view/create', 'params' => ['db' => null]], - ]; + $new->link = new Link( + $new->title, + '/view/create', + ['db' => null], + ); $this->addChild($new); } } diff --git a/tests/unit/Navigation/Nodes/NodeColumnContainerTest.php b/tests/unit/Navigation/Nodes/NodeColumnContainerTest.php index 9bf730efea..ef85730978 100644 --- a/tests/unit/Navigation/Nodes/NodeColumnContainerTest.php +++ b/tests/unit/Navigation/Nodes/NodeColumnContainerTest.php @@ -23,12 +23,8 @@ final class NodeColumnContainerTest extends AbstractTestCase 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]], - ], - $nodeColumnContainer->links, - ); + self::assertSame('/table/structure', $nodeColumnContainer->link->route); + self::assertSame(['db' => null, 'table' => null], $nodeColumnContainer->link->params); self::assertSame('columns', $nodeColumnContainer->realName); self::assertCount(1, $nodeColumnContainer->children); self::assertArrayHasKey(0, $nodeColumnContainer->children); @@ -44,14 +40,10 @@ final class NodeColumnContainerTest extends AbstractTestCase ['field_where' => 'last', 'after_field' => '', 'db' => null, 'table' => null], $newNode->icon->params, ); + self::assertSame('/table/add-field', $newNode->link->route); self::assertSame( - [ - 'text' => [ - 'route' => '/table/add-field', - 'params' => ['field_where' => 'last', 'after_field' => '', 'db' => null, 'table' => null], - ], - ], - $newNode->links, + ['field_where' => 'last', 'after_field' => '', 'db' => null, 'table' => null], + $newNode->link->params, ); } } diff --git a/tests/unit/Navigation/Nodes/NodeColumnTest.php b/tests/unit/Navigation/Nodes/NodeColumnTest.php index de7a4d8378..3d4afff99f 100644 --- a/tests/unit/Navigation/Nodes/NodeColumnTest.php +++ b/tests/unit/Navigation/Nodes/NodeColumnTest.php @@ -33,16 +33,12 @@ final class NodeColumnTest extends AbstractTestCase ['change_column' => 1, 'db' => null, 'table' => null, 'field' => null], $nodeColumn->icon->params, ); + self::assertSame('/table/structure/change', $nodeColumn->link->route); self::assertSame( - [ - 'text' => [ - 'route' => '/table/structure/change', - 'params' => ['change_column' => 1, 'db' => null, 'table' => null, 'field' => null], - ], - 'title' => 'Structure', - ], - $nodeColumn->links, + ['change_column' => 1, 'db' => null, 'table' => null, 'field' => null], + $nodeColumn->link->params, ); + self::assertSame('Structure', $nodeColumn->link->title); self::assertSame('field', $nodeColumn->urlParamName); } diff --git a/tests/unit/Navigation/Nodes/NodeDatabaseTest.php b/tests/unit/Navigation/Nodes/NodeDatabaseTest.php index d87d9c2678..bead4ad662 100644 --- a/tests/unit/Navigation/Nodes/NodeDatabaseTest.php +++ b/tests/unit/Navigation/Nodes/NodeDatabaseTest.php @@ -21,13 +21,9 @@ class NodeDatabaseTest extends AbstractTestCase public function testConstructor(): void { $parent = new NodeDatabase(new Config(), 'default'); - self::assertSame( - [ - 'text' => ['route' => '/database/structure', 'params' => ['db' => null]], - 'title' => 'Structure', - ], - $parent->links, - ); + self::assertSame('/database/structure', $parent->link->route); + self::assertSame(['db' => null], $parent->link->params); + self::assertSame('Structure', $parent->link->title); 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 735455109f..daa876ff21 100644 --- a/tests/unit/Navigation/Nodes/NodeEventContainerTest.php +++ b/tests/unit/Navigation/Nodes/NodeEventContainerTest.php @@ -18,12 +18,8 @@ class NodeEventContainerTest extends AbstractTestCase public function testConstructor(): void { $parent = new NodeEventContainer(new Config()); - self::assertSame( - [ - 'text' => ['route' => '/database/events', 'params' => ['db' => null]], - ], - $parent->links, - ); + self::assertSame('/database/events', $parent->link->route); + self::assertSame(['db' => null], $parent->link->params); 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 2c2e5ea498..71f8bb7b43 100644 --- a/tests/unit/Navigation/Nodes/NodeEventTest.php +++ b/tests/unit/Navigation/Nodes/NodeEventTest.php @@ -18,15 +18,8 @@ class NodeEventTest extends AbstractTestCase public function testConstructor(): void { $parent = new NodeEvent(new Config(), 'default'); - self::assertSame( - [ - 'text' => [ - 'route' => '/database/events', - 'params' => ['edit_item' => 1, 'db' => null, 'item_name' => null], - ], - ], - $parent->links, - ); + self::assertSame('/database/events', $parent->link->route); + self::assertSame(['edit_item' => 1, 'db' => null, 'item_name' => null], $parent->link->params); 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 bbfffd8d2a..a63a66ca4d 100644 --- a/tests/unit/Navigation/Nodes/NodeFunctionContainerTest.php +++ b/tests/unit/Navigation/Nodes/NodeFunctionContainerTest.php @@ -18,12 +18,8 @@ class NodeFunctionContainerTest extends AbstractTestCase public function testConstructor(): void { $parent = new NodeFunctionContainer(new Config()); - self::assertSame( - [ - 'text' => ['route' => '/database/routines', 'params' => ['type' => 'FUNCTION', 'db' => null]], - ], - $parent->links, - ); + self::assertSame('/database/routines', $parent->link->route); + self::assertSame(['type' => 'FUNCTION', 'db' => null], $parent->link->params); 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 6ab67c057c..82094fbbe7 100644 --- a/tests/unit/Navigation/Nodes/NodeFunctionTest.php +++ b/tests/unit/Navigation/Nodes/NodeFunctionTest.php @@ -18,14 +18,10 @@ class NodeFunctionTest extends AbstractTestCase public function testConstructor(): void { $parent = new NodeFunction(new Config(), 'default'); + self::assertSame('/database/routines', $parent->link->route); self::assertSame( - [ - 'text' => [ - 'route' => '/database/routines', - 'params' => ['item_type' => 'FUNCTION', 'edit_item' => 1, 'db' => null, 'item_name' => null], - ], - ], - $parent->links, + ['item_type' => 'FUNCTION', 'edit_item' => 1, 'db' => null, 'item_name' => null], + $parent->link->params, ); self::assertSame('/database/routines', $parent->icon->route); self::assertSame( diff --git a/tests/unit/Navigation/Nodes/NodeIndexContainerTest.php b/tests/unit/Navigation/Nodes/NodeIndexContainerTest.php index 9aa55ae9fc..01c2375646 100644 --- a/tests/unit/Navigation/Nodes/NodeIndexContainerTest.php +++ b/tests/unit/Navigation/Nodes/NodeIndexContainerTest.php @@ -18,12 +18,8 @@ class NodeIndexContainerTest extends AbstractTestCase public function testConstructor(): void { $parent = new NodeIndexContainer(new Config()); - self::assertSame( - [ - 'text' => ['route' => '/table/structure', 'params' => ['db' => null, 'table' => null]], - ], - $parent->links, - ); + self::assertSame('/table/structure', $parent->link->route); + self::assertSame(['db' => null, 'table' => null], $parent->link->params); 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 594094fbf8..347da11bb9 100644 --- a/tests/unit/Navigation/Nodes/NodeIndexTest.php +++ b/tests/unit/Navigation/Nodes/NodeIndexTest.php @@ -18,12 +18,8 @@ class NodeIndexTest extends AbstractTestCase public function testConstructor(): void { $parent = new NodeIndex(new Config(), 'default'); - self::assertSame( - [ - 'text' => ['route' => '/table/indexes', 'params' => ['db' => null, 'table' => null, 'index' => null]], - ], - $parent->links, - ); + self::assertSame('/table/indexes', $parent->link->route); + self::assertSame(['db' => null, 'table' => null, 'index' => null], $parent->link->params); 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 fe88b1d7b5..7472ec3aaa 100644 --- a/tests/unit/Navigation/Nodes/NodeProcedureContainerTest.php +++ b/tests/unit/Navigation/Nodes/NodeProcedureContainerTest.php @@ -18,12 +18,8 @@ class NodeProcedureContainerTest extends AbstractTestCase public function testConstructor(): void { $parent = new NodeProcedureContainer(new Config()); - self::assertSame( - [ - 'text' => ['route' => '/database/routines', 'params' => ['type' => 'PROCEDURE', 'db' => null]], - ], - $parent->links, - ); + self::assertSame('/database/routines', $parent->link->route); + self::assertSame(['type' => 'PROCEDURE', 'db' => null], $parent->link->params); 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 abd8047847..88f37afb0c 100644 --- a/tests/unit/Navigation/Nodes/NodeProcedureTest.php +++ b/tests/unit/Navigation/Nodes/NodeProcedureTest.php @@ -18,14 +18,10 @@ class NodeProcedureTest extends AbstractTestCase public function testConstructor(): void { $parent = new NodeProcedure(new Config(), 'default'); + self::assertSame('/database/routines', $parent->link->route); self::assertSame( - [ - 'text' => [ - 'route' => '/database/routines', - 'params' => ['item_type' => 'PROCEDURE', 'edit_item' => 1, 'db' => null, 'item_name' => null], - ], - ], - $parent->links, + ['item_type' => 'PROCEDURE', 'edit_item' => 1, 'db' => null, 'item_name' => null], + $parent->link->params, ); self::assertSame('/database/routines', $parent->icon->route); self::assertSame( diff --git a/tests/unit/Navigation/Nodes/NodeTableContainerTest.php b/tests/unit/Navigation/Nodes/NodeTableContainerTest.php index d143ef61fe..45a5008479 100644 --- a/tests/unit/Navigation/Nodes/NodeTableContainerTest.php +++ b/tests/unit/Navigation/Nodes/NodeTableContainerTest.php @@ -18,12 +18,8 @@ class NodeTableContainerTest extends AbstractTestCase public function testConstructor(): void { $parent = new NodeTableContainer(new Config()); - self::assertSame( - [ - 'text' => ['route' => '/database/structure', 'params' => ['tbl_type' => 'table', 'db' => null]], - ], - $parent->links, - ); + self::assertSame('/database/structure', $parent->link->route); + self::assertSame(['tbl_type' => 'table', 'db' => null], $parent->link->params); self::assertSame('/database/structure', $parent->icon->route); self::assertSame(['tbl_type' => 'table', 'db' => null], $parent->icon->params); self::assertSame('tables', $parent->realName); diff --git a/tests/unit/Navigation/Nodes/NodeTableTest.php b/tests/unit/Navigation/Nodes/NodeTableTest.php index e7501e738d..357bbc5763 100644 --- a/tests/unit/Navigation/Nodes/NodeTableTest.php +++ b/tests/unit/Navigation/Nodes/NodeTableTest.php @@ -23,13 +23,9 @@ class NodeTableTest extends AbstractTestCase $config->settings['NavigationTreeDefaultTabTable2'] = '/table/change'; $parent = new NodeTable($config, 'default'); - self::assertSame( - [ - 'text' => ['route' => '/sql', 'params' => ['pos' => 0, 'db' => null, 'table' => null]], - 'title' => 'Browse', - ], - $parent->links, - ); + self::assertSame('/sql', $parent->link->route); + self::assertSame(['pos' => 0, 'db' => null, 'table' => null], $parent->link->params); + self::assertSame('Browse', $parent->link->title); self::assertSame('/table/search', $parent->icon->route); self::assertSame(['db' => null, 'table' => null], $parent->icon->params); self::assertNotNull($parent->secondIcon); diff --git a/tests/unit/Navigation/Nodes/NodeTriggerContainerTest.php b/tests/unit/Navigation/Nodes/NodeTriggerContainerTest.php index c7428cc6e5..202552ea48 100644 --- a/tests/unit/Navigation/Nodes/NodeTriggerContainerTest.php +++ b/tests/unit/Navigation/Nodes/NodeTriggerContainerTest.php @@ -18,12 +18,8 @@ class NodeTriggerContainerTest extends AbstractTestCase public function testConstructor(): void { $parent = new NodeTriggerContainer(new Config()); - self::assertSame( - [ - 'text' => ['route' => '/triggers', 'params' => ['db' => null, 'table' => null]], - ], - $parent->links, - ); + self::assertSame('/triggers', $parent->link->route); + self::assertSame(['db' => null, 'table' => null], $parent->link->params); 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 d7780bf9b9..1402edf213 100644 --- a/tests/unit/Navigation/Nodes/NodeTriggerTest.php +++ b/tests/unit/Navigation/Nodes/NodeTriggerTest.php @@ -18,14 +18,10 @@ class NodeTriggerTest extends AbstractTestCase public function testConstructor(): void { $parent = new NodeTrigger(new Config(), 'default'); + self::assertSame('/triggers', $parent->link->route); self::assertSame( - [ - 'text' => [ - 'route' => '/triggers', - 'params' => ['edit_item' => 1, 'db' => null, 'item_name' => null], - ], - ], - $parent->links, + ['edit_item' => 1, 'db' => null, 'item_name' => null], + $parent->link->params, ); self::assertSame('/triggers', $parent->icon->route); self::assertSame( diff --git a/tests/unit/Navigation/Nodes/NodeViewContainerTest.php b/tests/unit/Navigation/Nodes/NodeViewContainerTest.php index 27a59ef536..739e54c448 100644 --- a/tests/unit/Navigation/Nodes/NodeViewContainerTest.php +++ b/tests/unit/Navigation/Nodes/NodeViewContainerTest.php @@ -18,12 +18,8 @@ class NodeViewContainerTest extends AbstractTestCase public function testConstructor(): void { $parent = new NodeViewContainer(new Config()); - self::assertSame( - [ - 'text' => ['route' => '/database/structure', 'params' => ['tbl_type' => 'view', 'db' => null]], - ], - $parent->links, - ); + self::assertSame('/database/structure', $parent->link->route); + self::assertSame(['tbl_type' => 'view', 'db' => null], $parent->link->params); self::assertSame('/database/structure', $parent->icon->route); self::assertSame(['tbl_type' => 'view', 'db' => null], $parent->icon->params); self::assertSame('views', $parent->realName); diff --git a/tests/unit/Navigation/Nodes/NodeViewTest.php b/tests/unit/Navigation/Nodes/NodeViewTest.php index 14eec87c29..888e3c8405 100644 --- a/tests/unit/Navigation/Nodes/NodeViewTest.php +++ b/tests/unit/Navigation/Nodes/NodeViewTest.php @@ -18,12 +18,8 @@ class NodeViewTest extends AbstractTestCase public function testConstructor(): void { $parent = new NodeView(new Config(), 'default'); - self::assertSame( - [ - 'text' => ['route' => '/sql', 'params' => ['pos' => 0, 'db' => null, 'table' => null]], - ], - $parent->links, - ); + self::assertSame('/sql', $parent->link->route); + self::assertSame(['pos' => 0, 'db' => null, 'table' => null], $parent->link->params); self::assertSame('b_props', $parent->icon->image); self::assertSame('View', $parent->icon->title); self::assertSame('/table/structure', $parent->icon->route); From b6794bdf1f4ac4813ff22065ae6ffd3a246824a3 Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Fri, 13 Jun 2025 02:21:23 +0100 Subject: [PATCH 3/3] Drop Node::$title Signed-off-by: Kamil Tekiela --- src/Navigation/NavigationTree.php | 5 ++--- src/Navigation/Nodes/Node.php | 3 --- src/Navigation/Nodes/NodeColumnContainer.php | 4 ++-- src/Navigation/Nodes/NodeDatabaseContainer.php | 2 +- src/Navigation/Nodes/NodeEvent.php | 2 +- src/Navigation/Nodes/NodeEventContainer.php | 4 ++-- src/Navigation/Nodes/NodeFunction.php | 2 +- src/Navigation/Nodes/NodeFunctionContainer.php | 4 ++-- src/Navigation/Nodes/NodeIndex.php | 2 +- src/Navigation/Nodes/NodeIndexContainer.php | 4 ++-- src/Navigation/Nodes/NodeProcedure.php | 2 +- src/Navigation/Nodes/NodeProcedureContainer.php | 4 ++-- src/Navigation/Nodes/NodeTable.php | 3 +-- src/Navigation/Nodes/NodeTableContainer.php | 4 ++-- src/Navigation/Nodes/NodeTrigger.php | 2 +- src/Navigation/Nodes/NodeTriggerContainer.php | 4 ++-- src/Navigation/Nodes/NodeView.php | 2 +- src/Navigation/Nodes/NodeViewContainer.php | 4 ++-- tests/unit/Navigation/Nodes/NodeColumnContainerTest.php | 2 +- tests/unit/Navigation/Nodes/NodeTest.php | 1 - 20 files changed, 27 insertions(+), 33 deletions(-) diff --git a/src/Navigation/NavigationTree.php b/src/Navigation/NavigationTree.php index df027058b6..c04561fae5 100644 --- a/src/Navigation/NavigationTree.php +++ b/src/Navigation/NavigationTree.php @@ -813,7 +813,7 @@ class NavigationTree $groups[$key]->pos3 = $node->pos3; if ($node instanceof NodeTableContainer || $node instanceof NodeViewContainer) { $groups[$key]->link = new Link( - $groups[$key]->title, + '', $node->link->route, array_merge($node->link->params, ['tbl_group' => $key]), ); @@ -1160,9 +1160,8 @@ class NavigationTree $paths = $node->getPaths(); - $title = $node->link->title; $options[] = [ - 'title' => $title, + 'title' => $node->link->title, 'name' => $node->realName, 'data' => ['apath' => $paths['aPath'], 'vpath' => $paths['vPath'], 'pos' => $this->pos], 'isSelected' => $node->realName === $selected, diff --git a/src/Navigation/Nodes/Node.php b/src/Navigation/Nodes/Node.php index 9933654750..6d93c7770d 100644 --- a/src/Navigation/Nodes/Node.php +++ b/src/Navigation/Nodes/Node.php @@ -76,8 +76,6 @@ class Node public Link $link; - /** @var string HTML title */ - public string $title = ''; /** @var string Extra CSS classes for the node */ public string $classes = ''; /** @var bool Whether this node is a link for creating new objects */ @@ -126,7 +124,6 @@ class Node string $classes, ): Node { $node = new Node($this->config, $name); - $node->title = $name; $node->isNew = true; $node->classes = $classes; diff --git a/src/Navigation/Nodes/NodeColumnContainer.php b/src/Navigation/Nodes/NodeColumnContainer.php index 1b1ff8acf9..b0b130e859 100644 --- a/src/Navigation/Nodes/NodeColumnContainer.php +++ b/src/Navigation/Nodes/NodeColumnContainer.php @@ -24,7 +24,7 @@ class NodeColumnContainer extends Node $this->icon = new Icon('pause', __('Columns'), '/table/structure', ['db' => null, 'table' => null]); $this->link = new Link( - $this->title, + '', '/table/structure', ['db' => null, 'table' => null], ); @@ -39,7 +39,7 @@ class NodeColumnContainer extends Node ['field_where' => 'last', 'after_field' => '', 'db' => null, 'table' => null], ); $new->link = new Link( - $new->title, + $newLabel, '/table/add-field', ['field_where' => 'last', 'after_field' => '', 'db' => null, 'table' => null], ); diff --git a/src/Navigation/Nodes/NodeDatabaseContainer.php b/src/Navigation/Nodes/NodeDatabaseContainer.php index ae3c6d08d5..b9fa313a9f 100644 --- a/src/Navigation/Nodes/NodeDatabaseContainer.php +++ b/src/Navigation/Nodes/NodeDatabaseContainer.php @@ -46,7 +46,7 @@ class NodeDatabaseContainer extends Node $newLabel = _pgettext('Create new database', 'New'); $new = $this->getInstanceForNewNode($newLabel, 'new_database italics'); $new->icon = new Icon('b_newdb', $newLabel, '/server/databases'); - $new->link = new Link($new->title, '/server/databases'); + $new->link = new Link($newLabel, '/server/databases'); $this->addChild($new); } } diff --git a/src/Navigation/Nodes/NodeEvent.php b/src/Navigation/Nodes/NodeEvent.php index 6c033eb4b2..dedcd56a4d 100644 --- a/src/Navigation/Nodes/NodeEvent.php +++ b/src/Navigation/Nodes/NodeEvent.php @@ -28,7 +28,7 @@ class NodeEvent extends NodeDatabaseChild ['edit_item' => 1, 'db' => null, 'item_name' => null], ); $this->link = new Link( - $this->title, + '', '/database/events', ['edit_item' => 1, 'db' => null, 'item_name' => null], ); diff --git a/src/Navigation/Nodes/NodeEventContainer.php b/src/Navigation/Nodes/NodeEventContainer.php index e88b79a381..6c34ca9486 100644 --- a/src/Navigation/Nodes/NodeEventContainer.php +++ b/src/Navigation/Nodes/NodeEventContainer.php @@ -23,7 +23,7 @@ class NodeEventContainer extends NodeDatabaseChildContainer $this->icon = new Icon('b_events', __('Events'), '/database/events', ['db' => null]); $this->link = new Link( - $this->title, + '', '/database/events', ['db' => null], ); @@ -33,7 +33,7 @@ class NodeEventContainer extends NodeDatabaseChildContainer $new = $this->getInstanceForNewNode($newLabel, 'new_event italics'); $new->icon = new Icon('b_event_add', $newLabel, '/database/events', ['add_item' => 1, 'db' => null]); $new->link = new Link( - $new->title, + $newLabel, '/database/events', ['add_item' => 1, 'db' => null], ); diff --git a/src/Navigation/Nodes/NodeFunction.php b/src/Navigation/Nodes/NodeFunction.php index 11b48a82ea..bf01088760 100644 --- a/src/Navigation/Nodes/NodeFunction.php +++ b/src/Navigation/Nodes/NodeFunction.php @@ -28,7 +28,7 @@ class NodeFunction extends NodeDatabaseChild ['item_type' => 'FUNCTION', 'execute_dialog' => 1, 'db' => null, 'item_name' => null], ); $this->link = new Link( - $this->title, + '', '/database/routines', ['item_type' => 'FUNCTION', 'edit_item' => 1, 'db' => null, 'item_name' => null], ); diff --git a/src/Navigation/Nodes/NodeFunctionContainer.php b/src/Navigation/Nodes/NodeFunctionContainer.php index 7fd40013c7..93d9634163 100644 --- a/src/Navigation/Nodes/NodeFunctionContainer.php +++ b/src/Navigation/Nodes/NodeFunctionContainer.php @@ -28,7 +28,7 @@ class NodeFunctionContainer extends NodeDatabaseChildContainer ['type' => 'FUNCTION', 'db' => null], ); $this->link = new Link( - $this->title, + '', '/database/routines', ['type' => 'FUNCTION', 'db' => null], ); @@ -43,7 +43,7 @@ class NodeFunctionContainer extends NodeDatabaseChildContainer ['item_type' => 'FUNCTION', 'add_item' => 1, 'db' => null], ); $new->link = new Link( - $new->title, + $newLabel, '/database/routines', ['item_type' => 'FUNCTION', 'add_item' => 1, 'db' => null], ); diff --git a/src/Navigation/Nodes/NodeIndex.php b/src/Navigation/Nodes/NodeIndex.php index d2f38f9feb..bcb41c0d62 100644 --- a/src/Navigation/Nodes/NodeIndex.php +++ b/src/Navigation/Nodes/NodeIndex.php @@ -28,7 +28,7 @@ class NodeIndex extends Node ['db' => null, 'table' => null, 'index' => null], ); $this->link = new Link( - $this->title, + '', '/table/indexes', ['db' => null, 'table' => null, 'index' => null], ); diff --git a/src/Navigation/Nodes/NodeIndexContainer.php b/src/Navigation/Nodes/NodeIndexContainer.php index f3eb33405f..68b115d4f7 100644 --- a/src/Navigation/Nodes/NodeIndexContainer.php +++ b/src/Navigation/Nodes/NodeIndexContainer.php @@ -24,7 +24,7 @@ class NodeIndexContainer extends Node $this->icon = new Icon('b_index', __('Indexes'), '/table/structure', ['db' => null, 'table' => null]); $this->link = new Link( - $this->title, + '', '/table/structure', ['db' => null, 'table' => null], ); @@ -39,7 +39,7 @@ class NodeIndexContainer extends Node ['create_index' => 1, 'added_fields' => 2, 'db' => null, 'table' => null], ); $new->link = new Link( - $new->title, + $newLabel, '/table/indexes', ['create_index' => 1, 'added_fields' => 2, 'db' => null, 'table' => null], ); diff --git a/src/Navigation/Nodes/NodeProcedure.php b/src/Navigation/Nodes/NodeProcedure.php index 524fb3a986..57cf03e306 100644 --- a/src/Navigation/Nodes/NodeProcedure.php +++ b/src/Navigation/Nodes/NodeProcedure.php @@ -28,7 +28,7 @@ class NodeProcedure extends NodeDatabaseChild ['item_type' => 'PROCEDURE', 'execute_dialog' => 1, 'db' => null, 'item_name' => null], ); $this->link = new Link( - $this->title, + '', '/database/routines', ['item_type' => 'PROCEDURE', 'edit_item' => 1, 'db' => null, 'item_name' => null], ); diff --git a/src/Navigation/Nodes/NodeProcedureContainer.php b/src/Navigation/Nodes/NodeProcedureContainer.php index 178911582f..57c1980a31 100644 --- a/src/Navigation/Nodes/NodeProcedureContainer.php +++ b/src/Navigation/Nodes/NodeProcedureContainer.php @@ -28,7 +28,7 @@ class NodeProcedureContainer extends NodeDatabaseChildContainer ['type' => 'PROCEDURE', 'db' => null], ); $this->link = new Link( - $this->title, + '', '/database/routines', ['type' => 'PROCEDURE', 'db' => null], ); @@ -43,7 +43,7 @@ class NodeProcedureContainer extends NodeDatabaseChildContainer ['add_item' => 1, 'db' => null], ); $new->link = new Link( - $new->title, + $newLabel, '/database/routines', ['add_item' => 1, 'db' => null], ); diff --git a/src/Navigation/Nodes/NodeTable.php b/src/Navigation/Nodes/NodeTable.php index 1a6a833e96..dc5458e61a 100644 --- a/src/Navigation/Nodes/NodeTable.php +++ b/src/Navigation/Nodes/NodeTable.php @@ -43,10 +43,9 @@ class NodeTable extends NodeDatabaseChild $this->config->settings['NavigationTreeDefaultTabTable2'], ['db' => null, 'table' => null], ); - $this->title = Util::getTitleForTarget($this->config->settings['DefaultTabTable']); $this->link = new Link( - $this->title, + Util::getTitleForTarget($this->config->settings['DefaultTabTable']), $this->config->settings['DefaultTabTable'], ['pos' => 0, 'db' => null, 'table' => null], ); diff --git a/src/Navigation/Nodes/NodeTableContainer.php b/src/Navigation/Nodes/NodeTableContainer.php index db2bdf7e4e..64f2c97795 100644 --- a/src/Navigation/Nodes/NodeTableContainer.php +++ b/src/Navigation/Nodes/NodeTableContainer.php @@ -23,7 +23,7 @@ class NodeTableContainer extends NodeDatabaseChildContainer $this->icon = new Icon('b_browse', __('Tables'), '/database/structure', ['tbl_type' => 'table', 'db' => null]); $this->link = new Link( - $this->title, + '', '/database/structure', ['tbl_type' => 'table', 'db' => null], ); @@ -34,7 +34,7 @@ class NodeTableContainer extends NodeDatabaseChildContainer $new = $this->getInstanceForNewNode($newLabel, 'new_table italics'); $new->icon = new Icon('b_table_add', $newLabel, '/table/create', ['db' => null]); $new->link = new Link( - $new->title, + $newLabel, '/table/create', ['db' => null], ); diff --git a/src/Navigation/Nodes/NodeTrigger.php b/src/Navigation/Nodes/NodeTrigger.php index 114df09087..037df74956 100644 --- a/src/Navigation/Nodes/NodeTrigger.php +++ b/src/Navigation/Nodes/NodeTrigger.php @@ -28,7 +28,7 @@ class NodeTrigger extends Node ['export_item' => 1, 'db' => null, 'item_name' => null], ); $this->link = new Link( - $this->title, + '', '/triggers', ['edit_item' => 1, 'db' => null, 'item_name' => null], ); diff --git a/src/Navigation/Nodes/NodeTriggerContainer.php b/src/Navigation/Nodes/NodeTriggerContainer.php index cdf3c7b74c..508de6b952 100644 --- a/src/Navigation/Nodes/NodeTriggerContainer.php +++ b/src/Navigation/Nodes/NodeTriggerContainer.php @@ -24,7 +24,7 @@ class NodeTriggerContainer extends Node $this->icon = new Icon('b_triggers', __('Triggers'), '/triggers', ['db' => null, 'table' => null]); $this->link = new Link( - $this->title, + '', '/triggers', ['db' => null, 'table' => null], ); @@ -34,7 +34,7 @@ class NodeTriggerContainer extends Node $new = $this->getInstanceForNewNode($newLabel, 'new_trigger italics'); $new->icon = new Icon('b_trigger_add', $newLabel, '/triggers', ['add_item' => 1, 'db' => null]); $new->link = new Link( - $new->title, + $newLabel, '/triggers', ['add_item' => 1, 'db' => null], ); diff --git a/src/Navigation/Nodes/NodeView.php b/src/Navigation/Nodes/NodeView.php index c42b62bf05..103e420298 100644 --- a/src/Navigation/Nodes/NodeView.php +++ b/src/Navigation/Nodes/NodeView.php @@ -23,7 +23,7 @@ class NodeView extends NodeDatabaseChild $this->icon = new Icon('b_props', __('View'), '/table/structure', ['db' => null, 'table' => null]); $this->link = new Link( - $this->title, + '', '/sql', ['pos' => 0, 'db' => null, 'table' => null], ); diff --git a/src/Navigation/Nodes/NodeViewContainer.php b/src/Navigation/Nodes/NodeViewContainer.php index 969b8e7c07..4738622201 100644 --- a/src/Navigation/Nodes/NodeViewContainer.php +++ b/src/Navigation/Nodes/NodeViewContainer.php @@ -23,7 +23,7 @@ class NodeViewContainer extends NodeDatabaseChildContainer $this->icon = new Icon('b_views', __('Views'), '/database/structure', ['tbl_type' => 'view', 'db' => null]); $this->link = new Link( - $this->title, + '', '/database/structure', ['tbl_type' => 'view', 'db' => null], ); @@ -34,7 +34,7 @@ class NodeViewContainer extends NodeDatabaseChildContainer $new = $this->getInstanceForNewNode($newLabel, 'new_view italics'); $new->icon = new Icon('b_view_add', $newLabel, '/view/create', ['db' => null]); $new->link = new Link( - $new->title, + $newLabel, '/view/create', ['db' => null], ); diff --git a/tests/unit/Navigation/Nodes/NodeColumnContainerTest.php b/tests/unit/Navigation/Nodes/NodeColumnContainerTest.php index ef85730978..f014e2c7ea 100644 --- a/tests/unit/Navigation/Nodes/NodeColumnContainerTest.php +++ b/tests/unit/Navigation/Nodes/NodeColumnContainerTest.php @@ -30,7 +30,7 @@ final class NodeColumnContainerTest extends AbstractTestCase self::assertArrayHasKey(0, $nodeColumnContainer->children); $newNode = $nodeColumnContainer->children[0]; self::assertSame('New', $newNode->name); - self::assertSame('New', $newNode->title); + self::assertSame('New', $newNode->link->title); self::assertTrue($newNode->isNew); self::assertSame('new_column italics', $newNode->classes); self::assertSame('b_column_add', $newNode->icon->image); diff --git a/tests/unit/Navigation/Nodes/NodeTest.php b/tests/unit/Navigation/Nodes/NodeTest.php index 0fbddcff0c..019900cfbe 100644 --- a/tests/unit/Navigation/Nodes/NodeTest.php +++ b/tests/unit/Navigation/Nodes/NodeTest.php @@ -531,7 +531,6 @@ final class NodeTest extends AbstractTestCase self::assertSame('New', $node->name); self::assertSame(NodeType::Object, $node->type); self::assertFalse($node->isGroup); - self::assertSame('New', $node->title); self::assertTrue($node->isNew); self::assertSame('new_database italics', $node->classes); }