laravel-menus icon indicating copy to clipboard operation
laravel-menus copied to clipboard

Bootstrap 4

Open drjoju opened this issue 8 years ago • 9 comments

Hi, https://blackrockdigital.github.io/startbootstrap-modern-business/ As you can see in the Bootstrap 4 menu, the first lavel of link has the class "nav-link". For example

<a class="nav-link" href="about.html">About</a> In the second level the class is different, For example. <a class="dropdown-item" href="portfolio-3-col.html">3 Column Portfolio</a>

As I see in the presenter there is only one place to set de class

    public function getMenuWithoutDropdownWrapper($item)
    {
        return '<li class="nav-item" ' . $this->getActiveState($item) . '><a class="nav-link" href="' . $item->getUrl() . '" ' . $item->getAttributes() . '>' . $item->getIcon() . ' ' . $item->title . '</a></li>' . PHP_EOL;
    }

How can we set the correct class in function of depth?

Thanks and best regards

drjoju avatar Sep 11 '17 15:09 drjoju

you can create a new presenter class for bootstrap 4.

nWidart avatar Sep 11 '17 15:09 nWidart

Yes, I do it but I don't know how to process the second level. I created a presenter like this one but I don't know if it's the best solution `

' . PHP_EOL; } public function getCloseTagWrapper() { return PHP_EOL . '' . PHP_EOL; } public function getMenuWithoutDropdownWrapper($item) { return '' . PHP_EOL; } public function getSubmenuWithoutDropdownWrapper($item) { return '' . PHP_EOL; } public function getActiveState($item, $state = ' class="active"') { return $item->isActive() ? $state : null; } public function getActiveStateOnChild($item, $state = 'active') { return $item->hasActiveOnChild() ? $state : null; } public function getDividerWrapper() { return '
  • '; } public function getHeaderWrapper($item) { return '
  • '; } public function getMenuWithDropDownWrapper($item) { return '' . PHP_EOL; } public function getMultiLevelDropdownWrapper($item) { return '' . PHP_EOL; } public function getChildMenuItems(MenuItem $item) { $results = ''; foreach ($item->getChilds() as $child) { if ($child->hidden()) { continue; } if ($child->hasSubMenu()) { $results .= $this->getMultiLevelDropdownWrapper($child); } elseif ($child->isHeader()) { $results .= $this->getHeaderWrapper($child); } elseif ($child->isDivider()) { $results .= $this->getDividerWrapper(); } else { $results .= $this->getSubmenuWithoutDropdownWrapper($child); } } return $results; } } ` What do you think? Thanks

    drjoju avatar Sep 11 '17 15:09 drjoju

    Plus format your post, this is unreadable :D

    nWidart avatar Sep 11 '17 15:09 nWidart

    Sorry,

    Basically I created a presenter based on NavbarPresenter and override the method getChildMenuItems.

    The part modified is

    
                if ($child->hasSubMenu()) {
                    $results .= $this->getMultiLevelDropdownWrapper($child);
                } elseif ($child->isHeader()) {
                    $results .= $this->getHeaderWrapper($child);
                } elseif ($child->isDivider()) {
                    $results .= $this->getDividerWrapper();
                } else {
                    $results .= $this->getSubmenuWithoutDropdownWrapper($child);
                }
    
    
    

    I introduce the method getSubmenuWithoutDropdownWrapper with this code

    
        public function getSubmenuWithoutDropdownWrapper($item)
        {
            return '<li class="nav-item" ' . $this->getActiveState($item) . '><a class="dropdown-item" href="' . $item->getUrl() . '" ' . $item->getAttributes() . '>' . $item->getIcon() . ' ' . $item->title . '</a></li>' . PHP_EOL;
        }
    
    

    This method write the correct class (dropdown-item) in the submenu.

    What do you think about this aproach?

    Thanks

    drjoju avatar Sep 11 '17 18:09 drjoju

    +1 for BS4 support out of the box. Would be great. Will see if I can submit a PR.

    vpratfr avatar Dec 21 '17 10:12 vpratfr

    Is there any solution at this point?

    philippschurig avatar Oct 08 '18 14:10 philippschurig

    i cant make a present with bootstrap 4 :(

    asaelmedina avatar Feb 15 '20 07:02 asaelmedina

    I did it. I used the idea of @drjoju . My implementation it was with AdminLTE 3 in SidebarMenuPresenter

    asaelmedina avatar Feb 15 '20 09:02 asaelmedina