Skip to content

Commit

Permalink
Merge branch 'release-1.0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
sakren committed Jun 1, 2014
2 parents 6837280 + a04e9a9 commit c206ca2
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 7 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ menu:
include:
- Book:add
- Book:edit
- Front:Book:detail # in module
- <module>:Book:delete # "dynamic" module
```

## Custom templates
Expand Down Expand Up @@ -334,9 +336,12 @@ class BookPresenter extends BasePresenter

## Changelog

* 1.0.2
+ Support for "dynamic" modules in includes option [#4](https://github.com/sakren/nette-menu/issues/4)

* 1.0.1
+ Include option can be array of targets [https://github.com/sakren/nette-menu/issues/1](#1)
+ Added support for translatable titles [https://github.com/sakren/nette-menu/issues/2](#2)
+ Include option can be array of targets [#1](https://github.com/sakren/nette-menu/issues/1)
+ Added support for translatable titles [#2](https://github.com/sakren/nette-menu/issues/2)

* 1.0.0
+ First version
44 changes: 39 additions & 5 deletions src/DK/Menu/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,36 @@ public function setInclude($include)
}


/**
* @return array|string
* @throws \DK\Menu\InvalidArgumentException
*/
public function getParsedInclude()
{
$include = $this->getInclude();
$name = $this->getMenu()->getPresenter()->getName();

if (($pos = mb_strpos($name, ':')) !== false) {
$module = mb_substr($name, 0, $pos);
$parse = function($include) use ($module) {
return strtr($include, array(
'<module>' => $module,
));
};

if (is_string($include)) {
return $parse($include);
} elseif (is_array($include)) {
return array_map($parse, $include);
} else {
throw new InvalidArgumentException;
}
}

return $include;
}


/**
* @return \DK\Menu\Item
*/
Expand Down Expand Up @@ -407,8 +437,12 @@ public function isAllowedForModule($module)
return true;
}

list($current) = explode(':', $this->getMenu()->getPresenter()->getName());
return ucfirst($module) === $current;
$name = $this->getMenu()->getPresenter()->getName();
if (($pos = mb_strpos($name, ':')) === false) {
return false;
}

return mb_substr($name, 0, $pos) === ucfirst($module);
}


Expand Down Expand Up @@ -448,8 +482,8 @@ public function isAllowed()
$this->isAllowedForRoles($this->getAllowedForRoles()) &&
(
$this->isAllowedForModule($this->getAllowedForModule()) ||
$this->isAllowedForParameters($this->getAllowedForParameters()
));
$this->isAllowedForParameters($this->getAllowedForParameters())
);
}

return $this->allowed;
Expand All @@ -476,7 +510,7 @@ public function isActive()
}

if ($this->active === null && $this->hasInclude()) {
$include = $this->getInclude();
$include = $this->getParsedInclude();
$name = $presenter->getName(). ':'. $presenter->getAction();

if (is_string($include) && preg_match('~'. $this->getInclude(). '~', $name)) {
Expand Down

0 comments on commit c206ca2

Please sign in to comment.