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

Commit

Permalink
Merge pull request #185 from EmmanuelVella/route-not-found
Browse files Browse the repository at this point in the history
Handle RouteNotFoundException
  • Loading branch information
dbu committed Apr 16, 2014
2 parents 455a409 + 260c336 commit bad1f7c
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions ContentAwareFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Symfony\Cmf\Bundle\MenuBundle;

use Knp\Menu\Silex\RouterAwareFactory;
use Knp\Menu\MenuFactory;
use Knp\Menu\ItemInterface;
use Knp\Menu\NodeInterface;
use Knp\Menu\MenuItem;
Expand All @@ -37,7 +37,7 @@
* The createItem method uses a voting process to decide whether the menu item
* is the current item.
*/
class ContentAwareFactory extends RouterAwareFactory
class ContentAwareFactory extends MenuFactory
{
/**
* @var UrlGeneratorInterface
Expand Down Expand Up @@ -83,7 +83,7 @@ public function __construct(
LoggerInterface $logger
)
{
parent::__construct($generator);
$this->generator = $generator;
$this->contentRouter = $contentRouter;
$this->linkTypes = array('route', 'uri', 'content');
$this->dispatcher = $dispatcher;
Expand Down Expand Up @@ -243,6 +243,22 @@ public function createItem($name, array $options = array())
break;
case 'route':
unset($options['uri']);

try {
$options['uri'] = $this->generator->generate(
$options['route'],
$options['routeParameters'],
$options['routeAbsolute']
);

unset($options['route']);
} catch (RouteNotFoundException $e) {
$this->logger->error(sprintf('%s : %s', $name, $e->getMessage()));

if (!$this->allowEmptyItems) {
return null;
}
}
break;
default:
throw new \RuntimeException(sprintf('Internal error: unexpected linkType "%s"', $options['linkType']));
Expand Down

0 comments on commit bad1f7c

Please sign in to comment.