Skip to content

Commit

Permalink
iconTemplate Configuration Added
Browse files Browse the repository at this point in the history
  • Loading branch information
cesurapp committed Apr 26, 2019
1 parent 3c48ec9 commit 96c5602
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 28 deletions.
8 changes: 4 additions & 4 deletions Builder/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Item implements ItemInterface
/**
* @var int
*/
private $id = null;
private $id;

/**
* @var string
Expand All @@ -38,7 +38,7 @@ class Item implements ItemInterface
/**
* @var int
*/
private $order = null;
private $order;

/**
* @var array
Expand Down Expand Up @@ -83,7 +83,7 @@ class Item implements ItemInterface
/**
* @var null | ItemInterface
*/
private $parent = null;
private $parent;

/**
* @var bool
Expand Down Expand Up @@ -289,7 +289,7 @@ public function getParent()
return $this->parent;
}

public function setParent(ItemInterface $item)
public function setParent(self $item)
{
if ($item === $this) {
throw new \InvalidArgumentException('Item cannot be a child of itself');
Expand Down
10 changes: 5 additions & 5 deletions Builder/ItemProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class ItemProcess implements ItemProcessInterface
/**
* ItemProcess constructor.
*
* @param RouterInterface $router
* @param RouterInterface $router
* @param AuthorizationCheckerInterface $security
*/
public function __construct(RouterInterface $router, AuthorizationCheckerInterface $security, EventDispatcherInterface $eventDispatcher)
Expand All @@ -62,15 +62,15 @@ public function __construct(RouterInterface $router, AuthorizationCheckerInterfa
* Menu Processor.
*
* @param ItemInterface $menu
* @param array $options
* @param array $options
*
* @return ItemInterface
*/
public function processMenu(ItemInterface $menu, array $options = []): ItemInterface
{
// Dispatch Event
if ($menu->isEvent()) {
$this->eventDispatcher->dispatch($menu->getId().'.event', new PdMenuEvent($menu));
$this->eventDispatcher->dispatch($menu->getId() . '.event', new PdMenuEvent($menu));
}

// Set Current URI
Expand All @@ -88,7 +88,7 @@ public function processMenu(ItemInterface $menu, array $options = []): ItemInter
* @param ItemInterface $menu
* @param $options
*/
private function recursiveProcess(ItemInterface &$menu, $options)
private function recursiveProcess(ItemInterface $menu, $options)
{
// Get Child Menus
$childs = $menu->getChild();
Expand Down Expand Up @@ -126,7 +126,7 @@ private function recursiveProcess(ItemInterface &$menu, $options)
}

// Set Child List Class
$child->setChildAttr(array_merge_recursive($child->getChildAttr(), ['class' => 'menu_level_'.$child->getLevel()]));
$child->setChildAttr(array_merge_recursive($child->getChildAttr(), ['class' => 'menu_level_' . $child->getLevel()]));

$this->recursiveProcess($child, $options);
}
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,11 @@ The creation process is very simple. You can specify additional options.
You can change the default options.
```twig
{{ pd_menu_render('App\\Menu\\FirstMenu', {
'template': '@PdMenu/Default/menu.html.twig'
'depth': null
'currentClass': 'active'
'trans_domain': 'admin'
'template': '@PdMenu/Default/menu.html.twig',
'depth': null,
'currentClass': 'active',
'trans_domain': 'admin',
'iconTemplate' => '<i class="material-icons">itext</i>'
}) }}
```

Expand Down
14 changes: 4 additions & 10 deletions Render/TwigRender.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace Pd\MenuBundle\Render;

use Pd\MenuBundle\Builder\ItemInterface;
use Twig\Environment;

/**
* Menu Twig Rendering.
Expand All @@ -23,30 +24,23 @@
class TwigRender implements RenderInterface
{
/**
* @var \Twig_Environment
* @var Twig_Environment
*/
private $engine;

/**
* TwigRender constructor.
*
* @param \Twig_Environment $engine
* @param Twig_Environment $engine
*/
public function __construct(\Twig_Environment $engine)
public function __construct(Environment $engine)
{
$this->engine = $engine;
}

/**
* Render Menu.
*
* @param ItemInterface $item
* @param array $options
*
* @throws \Twig_Error_Loader
* @throws \Twig_Error_Runtime
* @throws \Twig_Error_Syntax
*
* @return string
*/
public function render(ItemInterface $item, array $options = []): string
Expand Down
6 changes: 3 additions & 3 deletions Resources/views/Default/menu.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
{% if menu.link %}
<a href="{{ menu.link }}" {{ arrayToAttr(menu.linkAttr, [], options) }}>
{% if menu.extra('label_icon') %}
<i class="material-icons">{{ menu.extra('label_icon') }}</i>
{{ options.iconTemplate|replace({ 'itext': menu.extra('label_icon') })|raw }}
{% endif %}
<span {{ arrayToAttr(menu.labelAttr, [], options) }}>
{{ menu.extra('label_translate', true) ? menu.label|trans([], options.trans_domain) : menu.label }}
{{ menu.extra('label_translate', true) ? menu.label|trans([], options.trans_domain)|raw : menu.label|raw }}
</span>
</a>
{% else %}
{% if menu.extra('label_icon') %}
<i class="material-icons">{{ menu.extra('label_icon') }}</i>
{{ options.iconTemplate|replace({ 'itext': menu.extra('label_icon') })|raw }}
{% endif %}
<span {{ arrayToAttr(menu.labelAttr, [], options) }}>
{{ menu.extra('label_translate', true) ? menu.label|trans([], options.trans_domain) : menu.label }}
Expand Down
3 changes: 2 additions & 1 deletion Twig/MenuExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ class MenuExtension extends AbstractExtension
'template' => '@PdMenu/Default/menu.html.twig',
'depth' => null,
'currentClass' => 'active',
'trans_domain' => null
'trans_domain' => null,
'iconTemplate' => '<i class="material-icons">itext</i>'
];

/**
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
}
],
"require": {
"php": "^7.1.3",
"php": "^7.2.1",
"twig/twig": "~2"
},
"autoload": {
Expand Down

0 comments on commit 96c5602

Please sign in to comment.