Código PHP:
namespace MusicaGenericoBundleMenu;
use KnpMenuFactoryInterface;
class MenuBuilder
{
private $container;
public function __construct($container)
{
$this->container = $container;
}
public function createPrincipalMenu(FactoryInterface $factory)
{
$translator = $this->container->get('translator');
$menu = $factory->createItem('root', array( 'navbar' => true,
'pull-right' => true,
)
);
$menu->addChild('INICIO', array('route' => 'temas_homepage'));
$drop_down_anos = $this->createDropdown($menu, $translator->trans('AÑOS'));
$this->cargarAnos($drop_down_anos);
$drop_down_letras = $this->createDropdown($menu, $translator->trans('ARTISTAS'));
$this->cargarLetras($drop_down_letras);
$drop_down_buscar = $this->createDropdown($menu, $translator->trans('BUSCAR'));
$templating = $this->container->get('templating');
$drop_down_buscar->addChild($templating->render(':menus:form.busqueda.html.twig'), array('extras' => array('safe_label' => true)));
$menu->addChild('CONTACTO', array('route' => 'contacto'));
return $menu;
}
private function createDropdown(KnpMenuMenuItem $menu, $nombre)
{
return $menu->addChild($nombre, array(
'dropdown' => true,
'caret' => true,
));
}
private function cargarAnos(KnpMenuMenuItem $drop_down)
{
$array_anos = array(1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 1900);
foreach ($array_anos as $ano){
$drop_down->addChild( (($ano == 1900) ? '?' : $ano) ,
array( 'route' => 'videos_temas_del_ano',
'routeParameters' => array('ano' => $ano)
)
);
}
}
private function cargarLetras(KnpMenuMenuItem $drop_down)
{
$array_letras = array('0-9','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');
foreach ($array_letras as $letra){
$drop_down->addChild( $letra ,
array( 'route' => 'videos_temas_de_artistas',
'routeParameters' => array('letra' => $letra)
)
);
}
}
}
Gracias.