avanzu / AdminThemeBundle

Admin Theme based on the AdminLTE Template for easy integration into symfony
MIT License
281 stars 149 forks source link

Create sidebar menu xxBundle\Model\MenuItemModel contains 16 abstract methods and must therefore be declared abstract or ... #248

Open Guiriou opened 5 years ago

Guiriou commented 5 years ago

I would like to create a menu sidebar navigation. I implemented the interface but I had this error: xxBundle\Model\MenuItemModel contains 16 abstract methods and must therefore be declared abstract or implement the remaining methods (Avanzu\AdminThemeBundle\Model\MenuItemInterface::getIdentifier, Avanzu\AdminThemeBundle\Model\MenuItemInterface::getLabel, Avanzu\AdminThemeBundle\Model\MenuItemInterface::getRoute, ...)

My code Model:

<?php
namespace jpBundle\Model

use Avanzu\AdminThemeBundle\Model\MenuItemInterface as ThemeMenuItem;

class MenuItemModel implements ThemeMenuItem {
    // ...
    // implement interface methods
    // ...
}

My code Event Listener:


<?php
namespace xxBundle\EventListener;

// ...

use xxBundle\Model\MenuItemModel;
use Avanzu\AdminThemeBundle\Event\SidebarMenuEvent;
use Symfony\Component\HttpFoundation\Request;

class MyMenuItemListListener {

    // ...

    public function onSetupMenu(SidebarMenuEvent $event) {

        $request = $event->getRequest();

        foreach ($this->getMenu($request) as $item) {
            $event->addItem($item);
        }

    }

    protected function getMenu(Request $request) {
        // Build your menu here by constructing a MenuItemModel array
        $menuItems = array(
            $blog = new MenuItemModel('ItemId', 'ItemDisplayName', 'jp_admin_abonnement', array(/* options */), 'iconclasses fa fa-plane')
        );

        // Add some children

        // A child with an icon
        $blog->addChild(new MenuItemModel('ChildOneItemId', 'ChildOneDisplayName', 'child_1_route', array(), 'fa fa-rss-square'));

        // A child with default circle icon
        $blog->addChild(new MenuItemModel('ChildTwoItemId', 'ChildTwoDisplayName', 'child_2_route'));
        return $this->activateByRoute($request->get('_route'), $menuItems);
    }

    protected function activateByRoute($route, $items) {

        foreach($items as $item) {
            if($item->hasChildren()) {
                $this->activateByRoute($route, $item->getChildren());
            }
            else {
                if($item->getRoute() == $route) {
                    $item->setIsActive(true);
                }
            }
        }

        return $items;
    }

}

Can you help me please?