Ejemplo n.º 1
0
 /**
  * Builds the menu with the given type and adds it into the layout service.
  *
  * If no name is specified for the menu a RuntimeException will be thrown.
  *
  * @param string|MenuTypeInterface $type
  * @param MenuInterface $menu
  * @throws \RuntimeException
  * @throws \Hw\BasicsBundle\Exception\UnexpectedTypeException
  * @return MenuInterface
  */
 public function create($type, MenuInterface $menu)
 {
     if (is_string($type)) {
         $type = $this->typeExtension->getType($type);
     }
     if (!$type instanceof MenuTypeInterface) {
         throw new UnexpectedTypeException($type, 'string or Hw\\BasicsBundle\\Menu\\MenuTypeInterface');
     }
     $type->build($menu);
     $key = $type->getName();
     if (!$key) {
         throw new \RuntimeException(sprintf('menu type %s returned no name', $key));
     }
     $menu->setName($type->getName());
     $this->layoutservice->addMenu($key, $menu);
     return $menu;
 }
 /**
  * Returns all menu items for the given menu key.
  *
  * @param string $key
  * @return MenuItem[]|null
  */
 public function getMenu($key)
 {
     return $this->layoutService->getMenuItems($key);
 }