Files
core/app/CMS/MenuPresenters/FoundationDrilldownMenuPresenter.php
T

83 lines
2.0 KiB
PHP

<?php
namespace App\CMS\MenuPresenters;
use Nwidart\Menus\MenuItem;
use Nwidart\Menus\Presenters\Presenter;
class FoundationDrilldownMenuPresenter extends Presenter
{
/**
* {@inheritdoc }
*/
public function getOpenTagWrapper()
{
return PHP_EOL . '<ul class="vertical menu" data-drilldown>' . PHP_EOL;
}
/**
* {@inheritdoc }
*/
public function getCloseTagWrapper()
{
return PHP_EOL . '</ul>' . PHP_EOL;
}
/**
* {@inheritdoc }
*/
public function getMenuWithoutDropdownWrapper($item)
{
return '<li' . $this->getActiveState($item) . '><a href="' . $item->getUrl() . '">' . $item->getIcon() . ' ' . $item->title . '</a></li>' . PHP_EOL;
}
/**
* {@inheritdoc }
*/
public function getActiveState(MenuItem $item)
{
$active = ' class="active"';
if (empty($item->getChilds())) {
// for direct menu input return if page is active
return \Request::is($item->getRequest()) ? $active : null;
} else {
// on nested menu inputs loop over children and in case any of them is active, mark active also root level
foreach ($item->getChilds() as $child) {
if ($this->getActiveState($child)) {
return $active;
}
}
}
return null;
}
/**
* {@inheritdoc }
*/
public function getDividerWrapper()
{
return '<li class="divider"></li>' . PHP_EOL;
}
public function getMultiLevelDropdownWrapper($item)
{
return $this->getMenuWithDropDownWrapper($item);
}
/**
* {@inheritdoc }
*/
public function getMenuWithDropDownWrapper($item)
{
$active = $this->getActiveState($item);
return '<li>
<a ' . $active . ' href="#">' . $item->getIcon() . ' ' . $item->title . '</a>
<ul class="vertical menu">
' . $this->getChildMenuItems($item) . '
</ul>
</li>' . PHP_EOL;
}
}