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

Menu Bundle Laravel Package

symfony-cmf/menu-bundle

Symfony CMF MenuBundle integrates dynamic, CMS-driven navigation into Symfony apps, building menus from content repositories with rich node metadata. Provides menu rendering, routing-aware items, and admin-friendly structure for complex site navigation.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add the bundle to your composer.json:

    composer require symfony-cmf/menu-bundle
    

    Register the bundle in config/bundles.php (Symfony 4+):

    return [
        // ...
        SymfonyCmf\Bundle\MenuBundle\SymfonyCmfMenuBundle::class => ['all' => true],
    ];
    
  2. Configuration Extend KnpMenuBundle config in config/packages/knp_menu.yaml:

    knp_menu:
        twig:
            template: 'SymfonyCmfMenuBundle:Menu:menu.html.twig'
        repositories:
            - SymfonyCmf\Bundle\MenuBundle\Repository\PhpcrMenuRepository
    
  3. First Use Case Create a PHPCR document for a menu (e.g., MenuNode):

    use SymfonyCmf\Bundle\MenuBundle\Document\MenuNode;
    
    $menuNode = new MenuNode();
    $menuNode->setTitle('Main Menu');
    $dm->persist($menuNode);
    $dm->flush();
    

    Render it in Twig:

    {{ knp_menu_render('main_menu', {'rootNode': menuNode}) }}
    

Implementation Patterns

Workflows

  1. Dynamic Menu Generation Use PHPCR queries to fetch menu nodes dynamically:

    $menuRepository = $dm->getRepository(MenuNode::class);
    $menuItems = $menuRepository->findBy(['parent' => $parentNode]);
    
  2. Caching Strategies Leverage Symfony’s cache system with knp_menu.cache:

    knp_menu:
        cache:
            prefix: 'cmf_menu_'
            default_lifetime: 3600
    
  3. Integration with SymfonyCmf Routing Link menu nodes to routes via MenuNode properties:

    $menuNode->setRoute('homepage');
    $menuNode->setRouteParameters(['_locale' => 'en']);
    
  4. Twig Extensions Customize menu rendering with Twig:

    {% for item in menu %}
        <li class="{{ item.isActive ? 'active' }}">
            <a href="{{ path(item.route, item.routeParameters) }}">{{ item.title }}</a>
        </li>
    {% endfor %}
    
  5. Event Listeners Hook into MenuBuilder events for dynamic modifications:

    use SymfonyCmf\Bundle\MenuBundle\Event\MenuBuilderEvent;
    
    $event->getMenu()->addChild('admin', ['route' => 'admin_dashboard']);
    

Gotchas and Tips

Pitfalls

  1. PHPCR Dependency

    • Requires PHPCR ODM (doctrine/doctrine-phpcr-odm-bundle). Ensure it’s installed and configured.
    • Debug PHPCR connection issues with:
      php bin/console doctrine:phpcr:debug
      
  2. Menu Caching Quirks

    • Clear cache after menu updates:
      php bin/console cache:clear
      
    • Use knp_menu.cache_lifetime: 0 for development to disable caching.
  3. Route Resolution

    • Ensure MenuNode routes exist in Symfony’s router. Use:
      $menuNode->setRoute('non_existent_route'); // Throws exception if route doesn’t exist.
      
  4. Archived Package Risks

    • No active maintenance. Fork or patch locally if critical bugs arise.
    • Prefer alternatives like cmf/routing for new projects.

Tips

  1. Debugging Menu Structure Dump menu nodes in Twig:

    {{ dump(menu) }}
    

    Or in PHP:

    var_dump($menuNode->getChildren());
    
  2. Performance

    • Use findBy with HINT_LOOKUP for large menus:
      $qb = $dm->createQueryBuilder(MenuNode::class);
      $qb->where('node.parent = :parent')->setHint('HINT_LOOKUP', true);
      
  3. Custom Document Types Extend MenuNode for domain-specific fields:

    use SymfonyCmf\Bundle\MenuBundle\Document\MenuNode as BaseMenuNode;
    
    class CustomMenuNode extends BaseMenuNode {
        private $customField;
        // ...
    }
    
  4. Symfony 5+ Compatibility

    • Override SymfonyCmfMenuBundle in config/bundles.php to force autoloading:
      SymfonyCmf\Bundle\MenuBundle\SymfonyCmfMenuBundle::class => ['all' => true, 'autoload' => true],
      
  5. Testing Mock PHPCR in tests:

    $this->dm->expects($this)->method('find')->willReturn($menuNode);
    
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.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui