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

Commit bad1f7c

Browse files
committed
Merge pull request #185 from EmmanuelVella/route-not-found
Handle RouteNotFoundException
2 parents 455a409 + 260c336 commit bad1f7c

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

ContentAwareFactory.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Symfony\Cmf\Bundle\MenuBundle;
1313

14-
use Knp\Menu\Silex\RouterAwareFactory;
14+
use Knp\Menu\MenuFactory;
1515
use Knp\Menu\ItemInterface;
1616
use Knp\Menu\NodeInterface;
1717
use Knp\Menu\MenuItem;
@@ -37,7 +37,7 @@
3737
* The createItem method uses a voting process to decide whether the menu item
3838
* is the current item.
3939
*/
40-
class ContentAwareFactory extends RouterAwareFactory
40+
class ContentAwareFactory extends MenuFactory
4141
{
4242
/**
4343
* @var UrlGeneratorInterface
@@ -83,7 +83,7 @@ public function __construct(
8383
LoggerInterface $logger
8484
)
8585
{
86-
parent::__construct($generator);
86+
$this->generator = $generator;
8787
$this->contentRouter = $contentRouter;
8888
$this->linkTypes = array('route', 'uri', 'content');
8989
$this->dispatcher = $dispatcher;
@@ -243,6 +243,22 @@ public function createItem($name, array $options = array())
243243
break;
244244
case 'route':
245245
unset($options['uri']);
246+
247+
try {
248+
$options['uri'] = $this->generator->generate(
249+
$options['route'],
250+
$options['routeParameters'],
251+
$options['routeAbsolute']
252+
);
253+
254+
unset($options['route']);
255+
} catch (RouteNotFoundException $e) {
256+
$this->logger->error(sprintf('%s : %s', $name, $e->getMessage()));
257+
258+
if (!$this->allowEmptyItems) {
259+
return null;
260+
}
261+
}
246262
break;
247263
default:
248264
throw new \RuntimeException(sprintf('Internal error: unexpected linkType "%s"', $options['linkType']));

0 commit comments

Comments
 (0)