Skip to content

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

Open

Description

@lodaelise

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions