-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wrote Twig extension and event listener. Added addBreadcrumbs() and c…
…aching for getBreadcrumbs() into BreadcrumbService. Added tests for routes with prefixes and for routes without requirements.
- Loading branch information
Peter Hillerström
committed
Jul 2, 2012
1 parent
4f06606
commit da13663
Showing
13 changed files
with
299 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,24 +11,33 @@ | |
* | ||
* @author Peter Hillerström <[email protected]> | ||
*/ | ||
class BreadcrumbsListener extends Controller | ||
class BreadcrumbListener extends Controller | ||
{ | ||
|
||
/** | ||
* @var ContainerInterface | ||
*/ | ||
protected $container; | ||
|
||
public function __construct(/* ContainerInterface */ $container) | ||
public function __construct($container) | ||
{ | ||
$this->container = $container; | ||
$this->service = $this->container->get('xi_breadcrumbs'); | ||
$this->router = $this->container->get('router'); | ||
} | ||
|
||
public function onKernelController(/* FilterControllerEvent */ $event) | ||
public function onKernelController(FilterControllerEvent $event) | ||
{ | ||
$logger = $this->container->get('logger'); | ||
$logger->debug('Got kernel.controller event'); | ||
if (!is_array($controller = $event->getController())) { | ||
return; | ||
} | ||
|
||
/* $router = $this->container->get('router'); */ | ||
$controller = $event->getController(); | ||
$request = $event->getRequest(); | ||
|
||
$route = $request->get('_route'); | ||
$params = $this->router->match($request->getRequestUri()); | ||
|
||
$this->service->addBreadcrumbs($route, $params); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,18 @@ | ||
XiBreadcrumbsBundle_homepage: | ||
hello: | ||
pattern: /hello/{name} | ||
defaults: { _controller: XiBreadcrumbsBundle:Default:index } | ||
defaults: | ||
_controller: XiBreadcrumbsBundle:Default:index | ||
label: "hello {name}" | ||
name: "stranger" | ||
|
||
doing: | ||
pattern: /hello/{name}/do/{thing} | ||
defaults: | ||
_controller: XiBreadcrumbsBundle:Default:index | ||
parent: "hello" | ||
label: "doing {thing}" | ||
name: "stranger" | ||
thing: "that" | ||
requirements: | ||
name: "\w+" | ||
thing: "\w+" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{% if breadcrumbs|length %} | ||
<ul id="xi-breadcrumbs"> | ||
{% for bc in breadcrumbs %} | ||
{% if loop.last or not bc.url %} | ||
<li>{{ bc.label }}</li> | ||
{% else %} | ||
<li><a href="{{ bc.url }}">{{ bc.label }}</a></li> | ||
{% endif %} | ||
{% endfor %} | ||
</ul> | ||
{% endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,9 @@ | ||
Hello {{ name }}! | ||
<html> | ||
<head> | ||
<title>Hello {{ name }}!</title> | ||
</head> | ||
<body> | ||
<p>{{ xi_breadcrumbs() }}</p> | ||
<h1>Hello {{ name }}!</h1> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
hello: | ||
pattern: /hello/{name} | ||
defaults: | ||
_controller: XiBreadcrumbsBundle:Default:index | ||
label: "hello {name}" | ||
name: "stranger" | ||
|
||
doing: | ||
pattern: /hello/{name}/do/{thing} | ||
defaults: | ||
_controller: XiBreadcrumbsBundle:Default:index | ||
parent: "hello" | ||
label: "doing {thing}" | ||
name: "stranger" | ||
thing: "that" | ||
requirements: | ||
name: "\w+" | ||
thing: "\w+" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
home: | ||
pattern: /home | ||
|
||
prefix: | ||
resource: "simple.yml" | ||
prefix: /prefix |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.