From c065fb7d7a635e22571e32bd40b50f3ef95d72c8 Mon Sep 17 00:00:00 2001 From: Adam Binnersley Date: Mon, 7 Oct 2024 15:44:08 +0100 Subject: [PATCH] Add additional flexibility --- src/Navigation.php | 68 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 62 insertions(+), 6 deletions(-) diff --git a/src/Navigation.php b/src/Navigation.php index 7317d15..123969b 100644 --- a/src/Navigation.php +++ b/src/Navigation.php @@ -67,6 +67,18 @@ class Navigation */ public $navigationClass = 'nav navbar-nav'; + /** + * The class a li item should have + * @var string + */ + public $itemClass = ''; + + /** + * The class that should be given to all a elements + * @var string + */ + public $linkClass = ''; + /** * The HTML ID assigned to the menu item * @var string @@ -169,6 +181,50 @@ public function getActiveClass() return $this->activeClass; } + /** + * Returns the class given to link items + * @return string + */ + public function getItemClass() + { + return $this->itemClass; + } + + /** + * Sets a class to assign to all link items + * @param string $className + * @return $this + */ + public function setItemClass($className) + { + if (Check::checkIfStringSet($className)) { + $this->itemClass = trim($className); + } + return $this; + } + + /** + * Gets the class assigned to all link elements + * @return string + */ + public function getLinkClass() + { + return $this->linkClass; + } + + /** + * Sets the class to assign to all link elements + * @param string $className + * @return $this + */ + public function setLinkClass($className) + { + if (Check::checkIfStringSet($className)) { + $this->linkClass = trim($className); + } + return $this; + } + /** * Sets the class(es) for the HTML navigation item * @param string $classes This should be the class or lasses that you want to give to the navigation item @@ -357,7 +413,7 @@ public function createNavigation($levels = 0, $startLevel = 0) */ protected function buildMenu($it, $text, $link, $levels, $start) { - $current = Check::checkIfSet($this->checkLinkOffsetMatch($link, $it->getDepth()), ' class="'.$this->getActiveClass().'"'); + $current = Check::checkIfSet($this->checkLinkOffsetMatch($link, $it->getDepth()), ' '.$this->getActiveClass()); if ($start === 0 || $this->checkLinkOffsetMatch($link, ($start - 1)) || $this->sub === true) { if ($start !== 0 && $this->checkLinkOffsetMatch($link, ($start - 1))) { @@ -380,7 +436,7 @@ protected function nextItem($it, $start, $current) if ($this->sub === true && ($start - 1) == $it->getDepth()) { $this->sub = false; } else { - $this->navItem.= Check::greaterThanOrEqual($this->linkCount, 1, '').''; + $this->navItem.= Check::greaterThanOrEqual($this->linkCount, 1, '').'
  • '; } } @@ -402,7 +458,7 @@ protected function buildItem($it, $text, $link, $start, $current) $this->nextItem($it, $start, $current); } elseif ($this->currentLevel < $it->getDepth()) { for ($i = $this->currentLevel; $i < $it->getDepth(); $i++) { - $this->navItem.= 'getDropDownClass(), ' class="'.$this->getDropDownClass().'"').'>'; + $this->navItem.= 'getDropDownClass(), ' class="'.$this->getDropDownClass().'"').'>
  • '; } } else { for ($i = $it->getDepth(); $i < $this->currentLevel; $i++) { @@ -411,7 +467,7 @@ protected function buildItem($it, $text, $link, $start, $current) $this->nextItem($it, $start, $current); } } elseif ($start === 0 || ($this->sub === true && $it->getDepth() >= $start)) { - $this->navItem.= ''; + $this->navItem.= '
  • '; } $this->currentLevel = $it->getDepth(); @@ -437,7 +493,7 @@ protected function closeLevel() protected function createLinkItem($link, $text, $start, $depth) { if ($this->checkLinkOffsetMatch($link, 0) || $this->checkLinkOffsetMatch($link, 1) || $this->checkLinkOffsetMatch($link, 2) || $this->checkLinkOffsetMatch($link, 3)) { - $current = (($start >= 1 && $this->checkLinkOffsetMatch($link, 0) && isset($this->current[1]['link'])) ? '' : ' class="'.$this->getActiveClass().'"'); + $current = (($start >= 1 && $this->checkLinkOffsetMatch($link, 0) && isset($this->current[1]['link'])) ? '' : ' '.$this->getActiveClass().''); } else { $current = ''; } @@ -447,7 +503,7 @@ protected function createLinkItem($link, $text, $start, $depth) $href = ' href="'.$link.'"'; } $this->linkCount++; - return ''.$this->textWrap($text, $depth).''; + return ''.$this->textWrap($text, $depth).''; } /**