Skip to content

Commit 45165b5

Browse files
cugrifdustingraham
authored andcommitted
add caption (#249)
* add caption * make option * update readme * update readme nav
1 parent d740616 commit 45165b5

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ __For Laravel 4.x, check [version 1.5.0](https://github.com/lavary/laravel-menu/
3838
* [Active Item](#active-item)
3939
- [RESTful URLs](#restful-urls)
4040
- [URL Wildcards](#url-wildcards)
41+
- [Disable activation](#disable-activation)
4142
* [Inserting a Separator](#inserting-a-separator)
4243
* [Append and Prepend](#append-and-prepend)
4344
* [Before and After](#before-and-after)
@@ -775,6 +776,15 @@ $menu->add('Articles', 'articles')->active('this-is-another-url/*');
775776

776777
So `this-is-another-url`, `this-is-another-url/and-another` will both activate `Articles` item.
777778

779+
#### Disable activation
780+
Sometimes you may need to disable auto activation for single items.
781+
You can pass **disableActivationByURL** in options like this:
782+
```php
783+
$menu->add('Anchor', ['disableActivationByURL' => true, 'url' => '#']);
784+
```
785+
This prevents auto activation by matching URL.
786+
But activation for items with active children keeps working.
787+
778788
## Inserting a Separator
779789

780790
You can insert a separator after each item using `divide()` method:

src/Lavary/Menu/Item.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,14 @@ class Item
9999
*/
100100
public $isActive = false;
101101

102+
/**
103+
* If true this prevents auto activation by matching URL
104+
* Activation by active children keeps working.
105+
*
106+
* @var bool
107+
*/
108+
private $disableActivationByURL = false;
109+
102110
/**
103111
* Creates a new Item instance.
104112
*
@@ -125,6 +133,9 @@ public function __construct($builder, $id, $title, $options)
125133
} else {
126134
$path = Arr::only($options, array('url', 'route', 'action', 'secure'));
127135
}
136+
if (isset($options['disableActivationByURL']) && true == $options['disableActivationByURL']) {
137+
$this->disableActivationByURL = true;
138+
}
128139

129140
if (!is_null($path)) {
130141
$path['prefix'] = $this->builder->getLastGroupPrefix();
@@ -141,7 +152,7 @@ public function __construct($builder, $id, $title, $options)
141152
/**
142153
* Creates a sub Item.
143154
*
144-
* @param string $title
155+
* @param string $title
145156
* @param string|array $options
146157
* @return Item
147158
*/
@@ -352,6 +363,9 @@ public function all()
352363
*/
353364
public function checkActivationStatus()
354365
{
366+
if (true === $this->disableActivationByURL) {
367+
return;
368+
}
355369
if (true == $this->builder->conf['restful']) {
356370
$path = ltrim(parse_url($this->url(), PHP_URL_PATH), '/');
357371
$rpath = ltrim(parse_url(Request::path(), PHP_URL_PATH), '/');

0 commit comments

Comments
 (0)