Skip to content

Commit 5e8d009

Browse files
foxycodedavidkudera
authored andcommitted
Fixed link generation error when using modules introduced in PR #32
1 parent 13d3cd4 commit 5e8d009

File tree

3 files changed

+23
-23
lines changed

3 files changed

+23
-23
lines changed

README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,26 +39,26 @@ menu:
3939
items:
4040

4141
Home:
42-
action: :Front:Home:
42+
action: Front:Home:
4343

4444
Books:
4545
link: '#'
4646
items:
4747

4848
All:
49-
action: :Front:Books:all
49+
action: Front:Books:all
5050

5151
Featured:
52-
action: :Front:Books:featured
52+
action: Front:Books:featured
5353

5454
admin:
5555
items:
5656

5757
Users:
58-
action: :Admin:Users:
58+
action: Admin:Users:
5959

6060
Books:
61-
action: :Admin:Books:
61+
action: Admin:Books:
6262
```
6363
6464
```php
@@ -101,15 +101,15 @@ That structure in neon config will generate two menus:
101101

102102
**front:**
103103

104-
* Home (action: `:Front:Home:`)
104+
* Home (action: `Front:Home:`)
105105
* Books (link: `#`)
106-
+ All (action: `:Front:Books:all`)
107-
+ Featured (action: `:Front:Books:featured`)
106+
+ All (action: `Front:Books:all`)
107+
+ Featured (action: `Front:Books:featured`)
108108

109109
**admin:**
110110

111-
* Users (action: `:Admin:Users:`)
112-
* Books (action: `:Admin:Books:`)
111+
* Users (action: `Admin:Users:`)
112+
* Books (action: `Admin:Books:`)
113113

114114
## Templates
115115

@@ -147,7 +147,7 @@ menu:
147147
items:
148148
149149
Home:
150-
action: :Front:Home:
150+
action: Front:Home:
151151
visibility:
152152
menu: true
153153
breadcrumbs: false
@@ -165,10 +165,10 @@ menu:
165165
items:
166166
167167
Home:
168-
action: :Front:Home:
168+
action: Front:Home:
169169
include: '^Front\:Home\:[a-zA-Z\:]+$' # mark as active for all actions of "Front:Home:" presenter
170170
Books:
171-
action: :Front:Books:
171+
action: Front:Books:
172172
include: # mark as active for actions "Front:Books:default" and "Front:Books:edit"
173173
- '^Front\:Books\:default$'
174174
- '^Front\:Books\:edit$'
@@ -304,7 +304,7 @@ menu:
304304
items:
305305
306306
Home:
307-
action: :Front:Home:
307+
action: Front:Home:
308308
309309
Books:
310310
link: '#'

src/Carrooi/Menu/MenuItem.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,7 @@ public function isActive(): bool
6666

6767
if ($this->getAction() && ($presenter = $this->menu->getActivePresenter())) {
6868

69-
try {
70-
$presenter->link($this->getAction(), $this->getActionParameters());
71-
} catch (InvalidLinkException $e) {}
72-
73-
if ($presenter->getLastCreatedRequestFlag('current')) {
69+
if ($presenter->link('//this') === $this->linkGenerator->link($this)) {
7470
return $this->active = true;
7571
}
7672

tests/CarrooiTests/Menu/MenuItemTest.phpt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,18 @@ final class MenuItemTest extends TestCase
7474

7575
public function testIsActive_action_current(): void
7676
{
77-
$linkGenerator = $this->createMockLinkGenerator();
7877
$translator = $this->createMockTranslator();
7978
$request = $this->createMockHttpRequest();
8079
$itemFactory = $this->createMockMenuItemFactory();
8180

81+
$linkGenerator = $this->createMockLinkGenerator(function (MockInterface $linkGenerator) {
82+
$linkGenerator->shouldReceive('link')->andReturn('#');
83+
});
84+
8285
$menu = $this->createMockMenu(function (MockInterface $menu) {
8386
$menu->shouldReceive('getActivePresenter')->andReturn(
8487
$this->createMockPresenter(function(MockInterface $presenter) {
8588
$presenter->shouldReceive('link')->andReturn('#');
86-
$presenter->shouldReceive('getLastCreatedRequestFlag')->andReturn(true);
8789
})
8890
);
8991
});
@@ -100,16 +102,18 @@ final class MenuItemTest extends TestCase
100102

101103
public function testIsActive_include(): void
102104
{
103-
$linkGenerator = $this->createMockLinkGenerator();
104105
$translator = $this->createMockTranslator();
105106
$request = $this->createMockHttpRequest();
106107
$itemFactory = $this->createMockMenuItemFactory();
107108

109+
$linkGenerator = $this->createMockLinkGenerator(function (MockInterface $linkGenerator) {
110+
$linkGenerator->shouldReceive('link')->andReturn('#');
111+
});
112+
108113
$menu = $this->createMockMenu(function (MockInterface $menu) {
109114
$menu->shouldReceive('getActivePresenter')->andReturn(
110115
$this->createMockPresenter(function(MockInterface $presenter) {
111116
$presenter->shouldReceive('link')->andReturn('#');
112-
$presenter->shouldReceive('getLastCreatedRequestFlag')->andReturn(false);
113117
$presenter->shouldReceive('getName')->andReturn('Home');
114118
$presenter->shouldReceive('getAction')->andReturn('edit');
115119
})

0 commit comments

Comments
 (0)