Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bootstrap 4 #13

Open
drjoju opened this issue Sep 11, 2017 · 9 comments
Open

Bootstrap 4 #13

drjoju opened this issue Sep 11, 2017 · 9 comments

Comments

@drjoju
Copy link

drjoju commented Sep 11, 2017

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

@nWidart
Copy link
Owner

nWidart commented Sep 11, 2017

you can create a new presenter class for bootstrap 4.

@drjoju
Copy link
Author

drjoju commented Sep 11, 2017

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 '
  • getActiveState($item) . '>getAttributes() . '>' . $item->getIcon() . ' ' . $item->title . '
  • ' . PHP_EOL; } public function getSubmenuWithoutDropdownWrapper($item) { return '
  • getActiveState($item) . '>getAttributes() . '>' . $item->getIcon() . ' ' . $item->title . '
  • ' . 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 '
  • ' . $item->title . '
  • '; } public function getMenuWithDropDownWrapper($item) { return '
  • ' . $item->getIcon() . ' ' . $item->title . '
      ' . $this->getChildMenuItems($item) . '
  • ' . PHP_EOL; } public function getMultiLevelDropdownWrapper($item) { return '
  • ' . $item->getIcon() . ' ' . $item->title . '
      ' . $this->getChildMenuItems($item) . '
  • ' . 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

    @nWidart
    Copy link
    Owner

    nWidart commented Sep 11, 2017

    Plus format your post, this is unreadable :D

    @drjoju
    Copy link
    Author

    drjoju commented Sep 11, 2017

    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

    @vpratfr
    Copy link

    vpratfr commented Dec 21, 2017

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

    Repository owner deleted a comment from vpratfr Mar 17, 2018
    @philippschurig
    Copy link

    Is there any solution at this point?

    @asaelmedina
    Copy link

    i cant make a present with bootstrap 4 :(

    @asaelmedina
    Copy link

    asaelmedina commented Feb 15, 2020

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

    @asaelmedina
    Copy link

    SidebarMenuPresenter.txt

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    None yet
    Projects
    None yet
    Development

    No branches or pull requests

    5 participants