Skip to content
This repository has been archived by the owner on Sep 16, 2021. It is now read-only.

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wouterj committed Jan 9, 2016
1 parent e83201d commit b92af0c
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions Templating/MenuHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,23 +132,30 @@ public function getCurrentItem(Request $request)
*/
public function getCurrentNode(Request $request)
{
$repository = $this->managerRegistry->getManager($this->managerName)
->getRepository('Symfony\Cmf\Bundle\MenuBundle\Doctrine\Phpcr\MenuNode');

if ($request->attributes->has($this->contentObjectKey)) {
$content = $request->attributes->get($this->contentObjectKey);

return $this->managerRegistry->getManager($this->managerName)->getRepository('CmfMenuBundle:MenuNode')->findOneBy(array('content' => $content));
return $this->filterByLinkType($repository->findBy(array('content' => $content)), 'content');
}

if ($request->attributes->has($this->routeNameKey)) {
$route = $request->attributes->get($this->routeNameKey);

$nodes = $this->managerRegistry->getManager($this->managerName)->getRepository('CmfMenuBundle:MenuNode')->findBy(array('route' => $route));
if (1 === count($nodes)) {
return $nodes->first();
} else {
foreach ($nodes as $node) {
if ('route' === $node->getLinkType()) {
return $node;
}
return $this->filterByLinkType($repository->findBy(array('route' => $route)), 'route');
}
}

private function filterByLinkType($nodes, $type)
{
if (1 === count($nodes)) {
return $nodes->first();
} else {
foreach ($nodes as $node) {
if ($type === $node->getLinkType()) {
return $node;
}
}
}
Expand Down

0 comments on commit b92af0c

Please sign in to comment.