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

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

Open
Guiriou opened this issue Aug 15, 2018 · 0 comments

Comments

@Guiriou
Copy link

Guiriou commented Aug 15, 2018

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?

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

1 participant