Skip to content

Commit

Permalink
List Parent Activate Added
Browse files Browse the repository at this point in the history
  • Loading branch information
cesurapp committed May 6, 2019
1 parent fc4d9d1 commit f6e8350
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 21 deletions.
34 changes: 34 additions & 0 deletions Builder/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,21 @@ class Item implements ItemInterface
*/
private $label = '';

/**
* @var string
*/
private $labelAfterHtml = '';

/**
* @var string
*/
private $link = '';

/**
* @var string
*/
private $linkAfterHtml = '';

/**
* @var int
*/
Expand Down Expand Up @@ -130,6 +140,18 @@ public function setLabel(string $label)
return $this;
}

public function getLabelAfterHtml(): string
{
return $this->labelAfterHtml;
}

public function setLabelAfterHtml(string $html)
{
$this->labelAfterHtml = $html;

return $this;
}

public function getLink(): string
{
return $this->link;
Expand All @@ -142,6 +164,18 @@ public function setLink(string $link)
return $this;
}

public function getLinkAfterHtml(): string
{
return $this->linkAfterHtml;
}

public function setLinkAfterHtml(string $html)
{
$this->linkAfterHtml = $html;

return $this;
}

public function getOrder(): int
{
return $this->order;
Expand Down
36 changes: 34 additions & 2 deletions Builder/ItemInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,22 @@ public function getLabel(): string;
*/
public function setLabel(string $label);

/**
* Get Label After HTML
*
* @return string
*/
public function getLabelAfterHtml(): string;

/**
* Label After Append HTML
*
* @param string $html
*
* @return mixed
*/
public function setLabelAfterHtml(string $html);

/**
* Get Menu Item URL.
*
Expand All @@ -75,6 +91,22 @@ public function getLink(): string;
*/
public function setLink(string $link);

/**
* Get Link After HTML
*
* @return string
*/
public function getLinkAfterHtml(): string;

/**
* Label Link Append HTML
*
* @param string $html
*
* @return mixed
*/
public function setLinkAfterHtml(string $html);

/**
* Get Order Number.
*
Expand Down Expand Up @@ -102,7 +134,7 @@ public function getRoute(): array;
* Change Menu Route.
*
* @param string $route
* @param array $params
* @param array $params
*
* @return ItemInterface
*/
Expand Down Expand Up @@ -176,7 +208,7 @@ public function setLabelAttr(array $labelAttr);
* Get Extra Data Menu Item.
*
* @param string $name
* @param null $default
* @param null $default
*
* @return mixed
*/
Expand Down
36 changes: 18 additions & 18 deletions Builder/ItemProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,6 @@ public function processMenu(ItemInterface $menu, array $options = []): ItemInter

/**
* Process Menu Item.
*
* @param ItemInterface $menu
* @param $options
*/
private function recursiveProcess(ItemInterface $menu, $options)
{
Expand All @@ -100,12 +97,28 @@ private function recursiveProcess(ItemInterface $menu, $options)

// Sort Current Child
foreach ($childs as $child) {
$active = false;
// Set Child Process
if ($child->getChild()) {
// Set Menu Depth
if (null !== $options['depth'] && ($child->getLevel() >= $options['depth'])) {
$child->setChild([]);
break;
}

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

$active = $this->recursiveProcess($child, $options);
}

// Generate Route Link
if ($child->getRoute()) {
$child->setLink($this->router->generate($child->getRoute()['name'], $child->getRoute()['params']));

// Link Active Class
if ($this->currentUri === $child->getLink()) {
if (($this->currentUri === $child->getLink()) || $active) {
$active = true;
$child->setListAttr(array_merge_recursive($child->getListAttr(), ['class' => $options['currentClass']]));
}
}
Expand All @@ -116,20 +129,6 @@ private function recursiveProcess(ItemInterface $menu, $options)
unset($childs[$child->getId()]);
}
}

// Set Child Process
if ($child->getChild()) {
// Set Menu Depth
if (null !== $options['depth'] && ($child->getLevel() >= $options['depth'])) {
$child->setChild([]);
break;
}

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

$this->recursiveProcess($child, $options);
}
}

// Sort Item
Expand All @@ -139,5 +138,6 @@ private function recursiveProcess(ItemInterface $menu, $options)

// Set Childs
$menu->setChild($childs);
return $active;
}
}
6 changes: 5 additions & 1 deletion Resources/views/Default/menu.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,18 @@
<span {{ arrayToAttr(menu.labelAttr, [], options) }}>
{{ menu.extra('label_translate', true) ? menu.label|trans([], options.trans_domain)|raw : menu.label|raw }}
</span>
{{ menu.labelAfterHtml|raw }}
</a>
{{ menu.linkAfterHtml|raw }}
{% else %}
{% if menu.extra('label_icon') %}
{{ 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>
{{ menu.labelAfterHtml|raw }}
{{ menu.linkAfterHtml|raw }}
{% endif %}

{# Create Dropdown #}
Expand Down

0 comments on commit f6e8350

Please sign in to comment.