Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
additional breadcrumb and blocks support in twig renderer
- Loading branch information
Showing
7 changed files
with
98 additions
and
74 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
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,7 +11,6 @@ class MenuOptions | |
public function __construct(array $options) | ||
{ | ||
$this->options = $options; | ||
|
||
} | ||
|
||
/** | ||
|
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,66 @@ | ||
<?php | ||
namespace Millwright\MenuBundle\Menu\Renderer; | ||
|
||
use Knp\Menu\ItemInterface; | ||
use Knp\Menu\Matcher\MatcherInterface; | ||
|
||
/** | ||
* Millwright menu twig renderer | ||
*/ | ||
class BreadcrumbTwigRenderer extends TwigRenderer | ||
{ | ||
/** | ||
* @param \Twig_Environment $environment | ||
* @param string $template | ||
* @param MatcherInterface $matcher | ||
* @param array $defaultOptions | ||
*/ | ||
public function __construct( | ||
\Twig_Environment $environment, | ||
$template, | ||
MatcherInterface $matcher, | ||
array $defaultOptions = array()) | ||
{ | ||
$defaultOptions = array_merge(array( | ||
'block' => 'breadcrumb' | ||
), $defaultOptions); | ||
parent::__construct($environment, $template, $matcher, $defaultOptions); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
protected function getData(ItemInterface $item) | ||
{ | ||
$currentItem = $this->getCurrentItem($item->getRoot()); | ||
$data = $currentItem->getBreadcrumbsArray(); | ||
if(isset($data[0]) && empty($data[0]['uri'])) { | ||
array_shift($data); | ||
} | ||
|
||
return $data; | ||
} | ||
|
||
/** | ||
* Get current item | ||
* | ||
* @param ItemInterface $item | ||
* | ||
* @return ItemInterface|null | ||
*/ | ||
private function getCurrentItem(ItemInterface $item) | ||
{ | ||
foreach ($item->getChildren() as $child) { | ||
if ($this->matcher->isCurrent($child)) { | ||
return $child; | ||
} else { | ||
$child = $this->getCurrentItem($child); | ||
if ($child) { | ||
return $child; | ||
} | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
} |
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