Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Crud Bundle Laravel Package

araise/crud-bundle

View on GitHub
Deep Wiki
Context7

Menu Extension

This extension allows building a custom navigation menu.

Requirements

This extension requires the KnpLabs/KnpMenuBundle bundle. The bundle is already included in the CRUD Bundle.

Installation

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:

  1. create a new file in 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;
    }
}
  1. Add the Menu in services.yaml:
parameters:
    araise_crud.menu_builder.class: App\Menu\MenuBuilder

Usage

Customize your menu

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.

Add a definition to the menu

$menu = $this->factory->createItem('');
$this->addDefinition($menu, CustomerDefinition::class);

Add a definition menu with filter

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');

Submenu

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;
    }
}

Options

[php-doc-parser(araise/CrudBundle:src/Builder/DefinitionMenuBuilder.php:public const OPT_)]

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
comsave/common
alecsammon/php-raml-parser
chrome-php/wrench
lendable/composer-license-checker
typhoon/reflection
mesilov/moneyphp-percentage
mike42/gfx-php
bookdown/themes
aura/view
aura/html
aura/cli
povils/phpmnd
nayjest/manipulator
omnipay/tests
psr-mock/http-message-implementation
psr-mock/http-factory-implementation
psr-mock/http-client-implementation
voku/email-check
voku/urlify
rtheunissen/guzzle-log-middleware