This extension allows building a custom navigation menu.
This extension requires the KnpLabs/KnpMenuBundle bundle. The bundle is already included in the CRUD Bundle.
By default, the menu is created automatically. A menu item is displayed for the dashboard and all definitions. If you want to create your own menu, you can do it as follows:
src/Menu/MenuBuilder.php or you can copy it from the CRUD bundle and customize the namespace.
The file should look like this:declare(strict_types=1);
namespace App\Menu;
use Knp\Menu\ItemInterface;
use araise\CrudBundle\Builder\DefinitionMenuBuilder;
use araise\CrudBundle\Definition\FilterDefinition;
class MenuBuilder extends DefinitionMenuBuilder
{
public function createMainMenu(): ItemInterface
{
$menu = $this->factory->createItem('');
$menu->addChild('Dashboard', [
self::OPT_ROUTE => 'araise_crud_dashboard',
self::OPT_ATTR => [
self::OPT_ATTR_ICON => 'house-door',
],
]);
foreach ($this->definitionManager->getDefinitions() as $definition) {
$class = get_class($definition);
if ($class === FilterDefinition::class) {
continue;
}
$this->addDefinition($menu, $class);
}
return $menu;
}
public function createSubMenu(): ItemInterface
{
$menu = $this->factory->createItem('');
return $menu;
}
}
services.yaml:parameters:
araise_crud.menu_builder.class: App\Menu\MenuBuilder
You may want to create a sub navigation item at menu item Dashboard. You can do that as follows:
$menu = $this->factory->createItem('');
$dashboardMenu = $menu->addChild('Dashboard', [
self::OPT_ROUTE => 'araise_crud_dashboard',
self::OPT_ATTR => [
self::OPT_ATTR_ICON => 'house-door',
],
]);
$dashboardMenu->addChild('Statistics', [
self::OPT_ROUTE => 'statistics_route',
self::OPT_ATTR => [
self::OPT_ATTR_ICON => 'graph-down',
],
]);
In the Crud Bundle we use the Bootstrap Icons.
$menu = $this->factory->createItem('');
$this->addDefinition($menu, CustomerDefinition::class);
For example, we want to make a navigation point which shows me all orders in open status. This can be done as follows:
$this->addDefinition($doctorsMenu, OrderDefinition::class, [
self::OPT_ROUTE_PARAMETERS => [
'index_filter_column[0][0]' => 'status',
'index_filter_operator[0][0]' => 'equal',
'index_filter_value[0][0]' => 'open',
]
], 'Open Orders');
There is also a submenu, which is displayed at the very bottom of the navigation. It is suitable for settings, for example. Here, you can also change the icon of the menu. As shown in the first example above, you don't have to specify the icon though.
public function createSubMenu(): ItemInterface
{
$menu = $this->factory->createItem('Settings', [
self::OPT_ATTR => [
self::OPT_ATTR_ICON => 'gear-wide',
],
]);
$this->addDefinition($menu, UserSettingsDefinition::class);
return $menu;
}
}
[php-doc-parser(araise/CrudBundle:src/Builder/DefinitionMenuBuilder.php:public const OPT_)]
How can I help you explore Laravel packages today?