diff --git a/Builder/Item.php b/Builder/Item.php
index c515d60..36b6f0b 100644
--- a/Builder/Item.php
+++ b/Builder/Item.php
@@ -23,7 +23,7 @@ class Item implements ItemInterface
/**
* @var int
*/
- private $id = null;
+ private $id;
/**
* @var string
@@ -38,7 +38,7 @@ class Item implements ItemInterface
/**
* @var int
*/
- private $order = null;
+ private $order;
/**
* @var array
@@ -83,7 +83,7 @@ class Item implements ItemInterface
/**
* @var null | ItemInterface
*/
- private $parent = null;
+ private $parent;
/**
* @var bool
@@ -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');
diff --git a/Builder/ItemProcess.php b/Builder/ItemProcess.php
index 9927a49..6e5a410 100644
--- a/Builder/ItemProcess.php
+++ b/Builder/ItemProcess.php
@@ -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)
@@ -62,7 +62,7 @@ public function __construct(RouterInterface $router, AuthorizationCheckerInterfa
* Menu Processor.
*
* @param ItemInterface $menu
- * @param array $options
+ * @param array $options
*
* @return ItemInterface
*/
@@ -70,7 +70,7 @@ public function processMenu(ItemInterface $menu, array $options = []): ItemInter
{
// 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
@@ -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();
@@ -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);
}
diff --git a/README.md b/README.md
index 49fb935..8517a87 100644
--- a/README.md
+++ b/README.md
@@ -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' => 'itext'
}) }}
```
diff --git a/Render/TwigRender.php b/Render/TwigRender.php
index 0dce4e2..bdc6db2 100644
--- a/Render/TwigRender.php
+++ b/Render/TwigRender.php
@@ -14,6 +14,7 @@
namespace Pd\MenuBundle\Render;
use Pd\MenuBundle\Builder\ItemInterface;
+use Twig\Environment;
/**
* Menu Twig Rendering.
@@ -23,16 +24,16 @@
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;
}
@@ -40,13 +41,6 @@ public function __construct(\Twig_Environment $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
diff --git a/Resources/views/Default/menu.html.twig b/Resources/views/Default/menu.html.twig
index 375e6de..4536019 100644
--- a/Resources/views/Default/menu.html.twig
+++ b/Resources/views/Default/menu.html.twig
@@ -17,15 +17,15 @@
{% if menu.link %}
{% if menu.extra('label_icon') %}
- {{ menu.extra('label_icon') }}
+ {{ options.iconTemplate|replace({ 'itext': menu.extra('label_icon') })|raw }}
{% endif %}
- {{ 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 }}
{% else %}
{% if menu.extra('label_icon') %}
- {{ menu.extra('label_icon') }}
+ {{ options.iconTemplate|replace({ 'itext': menu.extra('label_icon') })|raw }}
{% endif %}
{{ menu.extra('label_translate', true) ? menu.label|trans([], options.trans_domain) : menu.label }}
diff --git a/Twig/MenuExtension.php b/Twig/MenuExtension.php
index 842b9bc..6218ef8 100644
--- a/Twig/MenuExtension.php
+++ b/Twig/MenuExtension.php
@@ -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' => 'itext'
];
/**
diff --git a/composer.json b/composer.json
index 83bfbf8..b8f26ea 100644
--- a/composer.json
+++ b/composer.json
@@ -17,7 +17,7 @@
}
],
"require": {
- "php": "^7.1.3",
+ "php": "^7.2.1",
"twig/twig": "~2"
},
"autoload": {