-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
13 changed files
with
226 additions
and
41 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 |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
namespace Everlution\NavigationBundle\Bridge; | ||
|
||
/** | ||
* Class NavigationAliasTranslator. | ||
* Class NavigationAliasContainer. | ||
* | ||
* @author Ivan Barlog <[email protected]> | ||
*/ | ||
|
41 changes: 41 additions & 0 deletions
41
src/DependencyInjection/Compiler/NestedRegistryCompilerPass.php
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,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Everlution\NavigationBundle\DependencyInjection\Compiler; | ||
|
||
use Everlution\Navigation\Nested\Registry; | ||
use Everlution\NavigationBundle\Bridge\NavigationAliasContainer; | ||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Definition; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
|
||
/** | ||
* Class NestedRegistryCompilerPass. | ||
* | ||
* @author Martin Lutter <[email protected]> | ||
*/ | ||
class NestedRegistryCompilerPass implements CompilerPassInterface | ||
{ | ||
public function process(ContainerBuilder $container) | ||
{ | ||
$registry = $container->findDefinition(Registry::class); | ||
$aliasContainer = $container->findDefinition(NavigationAliasContainer::class); | ||
$services = $container->findTaggedServiceIds('everlution.advanced_navigation'); | ||
|
||
foreach ($services as $id => $tags) { | ||
$registry->addMethodCall('addContainer', [new Reference($id)]); | ||
$this->addAlias($aliasContainer, $id, $tags); | ||
} | ||
} | ||
|
||
private function addAlias(Definition $container, string $id, array $tags) | ||
{ | ||
foreach ($tags as $tag) { | ||
if (array_key_exists('alias', $tag)) { | ||
$container->addMethodCall('addAlias', [$tag['alias'], $id]); | ||
} | ||
} | ||
} | ||
} |
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
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,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Everlution\NavigationBundle\Twig; | ||
|
||
use Everlution\Navigation\Item\ItemInterface; | ||
use Everlution\Navigation\Url\CannotProvideUrlForItemException; | ||
use Everlution\Navigation\Url\UrlProviderContainer; | ||
use Everlution\NavigationBundle\Bridge\Item\TranslatableItemLabelInterface; | ||
use Symfony\Component\Translation\TranslatorInterface; | ||
|
||
/** | ||
* Class Helper. | ||
* | ||
* @author Martin Lutter <[email protected]> | ||
*/ | ||
class ItemHelper | ||
{ | ||
/** @var TranslatorInterface */ | ||
private $translator; | ||
/** @var UrlProviderContainer */ | ||
private $urlProvider; | ||
|
||
public function __construct(TranslatorInterface $translator, UrlProviderContainer $urlProvider) | ||
{ | ||
$this->translator = $translator; | ||
$this->urlProvider = $urlProvider; | ||
} | ||
|
||
public function getLabel(ItemInterface $item, string $domain = null, string $locale = null): string | ||
{ | ||
$label = $item->getLabel(); | ||
$parameters = $label instanceof TranslatableItemLabelInterface ? $label->getParameters() : []; | ||
|
||
return $this->translator->trans($label->getValue(), $parameters, $domain, $locale); | ||
} | ||
|
||
public function getUrl(ItemInterface $item): string | ||
{ | ||
try { | ||
return $this->urlProvider->getUrl($item); | ||
} catch (CannotProvideUrlForItemException $exception) { | ||
return '#'; | ||
} | ||
} | ||
} |
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,56 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Everlution\NavigationBundle\Twig; | ||
|
||
use Twig\Environment; | ||
|
||
/** | ||
* Class NestedNavigationExtension. | ||
* | ||
* @author Martin Lutter <[email protected]> | ||
*/ | ||
class NestedNavigationExtension extends \Twig_Extension | ||
{ | ||
/** @var ItemHelper */ | ||
private $helper; | ||
/** @var NestedNavigationHelper */ | ||
private $navigationHelper; | ||
|
||
public function __construct(ItemHelper $helper, NestedNavigationHelper $navigationHelper) | ||
{ | ||
$this->helper = $helper; | ||
$this->navigationHelper = $navigationHelper; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function renderAdvancedNavigation( | ||
Environment $environment, | ||
string $identifier, | ||
string $template | ||
): string { | ||
return $environment->render( | ||
$template, | ||
[ | ||
'root' => $this->navigationHelper->getNavigation($identifier)->getCurrent(), | ||
'identifier' => $identifier, | ||
'helper' => $this->helper, | ||
'navigation_helper' => $this->navigationHelper, | ||
] | ||
); | ||
} | ||
|
||
public function getFunctions() | ||
{ | ||
return [ | ||
new \Twig_SimpleFunction( | ||
'render_advanced_navigation', | ||
[$this, 'renderAdvancedNavigation'], | ||
['needs_environment' => true, 'is_safe' => ['html']] | ||
), | ||
]; | ||
} | ||
} |
Oops, something went wrong.