namespace Cubist\Backpack\app\Magic\Menu;
use Cubist\Backpack\app\Magic\Models\CMSPage;
+use Cubist\Backpack\app\Template\Navigation;
use Illuminate\Support\Str;
class Item
*/
protected $_controller = [];
+ /**
+ * @var bool
+ */
+ protected $_breadcrumbs = true;
+
/**
* @param string $id
$all = $class::orderBy('lft')->get();
$this->setId('#root');
+ $this->setBreadcrumbs(false);
$this->setName($id);
$this->setChildrenFromData($all, null);
}
if (!$item->status) {
continue;
}
+
$this->addChildFromData($item, $data);
}
}
public function addChildFromData($data, $all)
{
$child = new PageItem();
+ if ($data->getUsedTemplate() instanceof Navigation) {
+ $child->setBreadcrumbs(false);
+ }
$child->initFromPage($data, $all);
$this->addChild($child);
}
$this->_controller = $controller;
}
+ /**
+ * @param bool $breadcrumbs
+ */
+ public function setBreadcrumbs(bool $breadcrumbs): void
+ {
+ $this->_breadcrumbs = $breadcrumbs;
+ }
+
+ public function getBreadcrumbHref()
+ {
+ return $this->getHref();
+ }
+
+ /**
+ * @return bool
+ */
+ public function isBreadcrumbs(): bool
+ {
+ return $this->_breadcrumbs;
+ }
+
/**
* @param $menu Menu
*/
// Also make a menu for the breadcrumbs - this one is simpler and doesn't have the submenu headings
$this->make('breadcrumbs', function ($menu) use ($nav) {
// Start with home link
- $menu = $menu->add('Home', '');
-
- foreach ($nav->getChildren() as $main) {
- foreach ($main->getChildren() as $child) {
- $parent = $menu->add($child->getTitle(), $child->getHref());
+ $menu = $menu->add(__('Accueil'), '');
+ $this->_addToBreadcrumbs($nav, $menu);
+ });
+ }
- // Handle items with submenus
- if ($child->hasChildren()) {
- foreach ($child->getChildren() as $subitem) {
- $parent->add($subitem->getTitle(), $subitem->getHref());
- }
- }
- }
+ /**
+ * @param $nav Item
+ * @param $menu \Lavary\Menu\Item
+ */
+ protected function _addToBreadcrumbs($nav, $menu)
+ {
+ if ($nav->getTitle() && $nav->isBreadcrumbs()) {
+ if (substr($nav->getBreadcrumbHref(), 0, 1) == '#') {
+ $parent = $menu->raw($nav->getTitle());
+ } else {
+ $parent = $menu->add($nav->getTitle(), $nav->getBreadcrumbHref());
}
- });
+ } else {
+ $parent = $menu;
+ }
+ if ($nav->hasChildren()) {
+ foreach ($nav->getChildren() as $child) {
+ $this->_addToBreadcrumbs($child, $parent);
+ }
+ }
}
}
public function setChildrenFromTemplate()
{
- $template=$this->getPage()->getUsedTemplate();
+ $template = $this->getPage()->getUsedTemplate();
$template->setMenuChildren($this);
}
return $this->getSlug();
}
+ public function getBreadcrumbHref()
+ {
+ if ($this->getPage()->template == 'first_redirection' && $this->hasChildren()) {
+ return '#';
+ } else if ($this->getPage()->template == 'internal_redirection') {
+ return '#';
+ } else if ($this->getPage()->template == 'redirection') {
+ return '#';
+ } else if ($this->getPage()->getUsedTemplate()->isVirtual()) {
+ return '#';
+ }
+
+ return $this->getHref();
+ }
+
public function getClasses()
{
$classes = parent::getClasses();