Download the PHP package braunstetter/menu-bundle without Composer

On this page you can find all versions of the php package braunstetter/menu-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package menu-bundle

MenuBundle

Scrutinizer Code Quality Build Status Total Downloads License

Overview

braunstetter/menu-bundle is a powerful tool designed to simplify the process of creating menus in your Symfony projects. It provides an easy and intuitive interface to create and configure various types of menus.

Benefits of using this bundle include:

Installation

To install the MenuBundle, simply run the following command:

composer require braunstetter/menu-bundle

Symfony flex does all the rest for you.

Usage

After installation, you can create a menu by creating a class implementing MenuInterface. This is an example of how to define a menu:

Icons

The base path for images is just the templates folder of your application. But since this value will just be passed into the Twig source function you can also use an alias like @my_bundle/images/svg/thunder.svg.

Twig helper

Inside your twig templates you can print the menu by using the menu() function and passing it the snake_cased class name.

The formatted result:

Note: no css is shipped with this bundle. But as you can see, a ready-to-be-styled html markup gets printed once you use the menu() function.

Types of MenuItems

There are additional MenuItem::system and MenuItem::section. These are just convenient static methods to generate MenuItem::linkToRoute items with an attr.class set to system/section for rendering. MenuItem::system and MenuItem::section both can have empty routes:

LinkToRoute

Parameter:

  1. The shown label - you are free to translate it right here or inside your custom template.
  2. Route name.
  3. Route Parameters.
  4. Icon (optional)

LinkToUrl

Parameter:

  1. Label
  2. Absolute url
  3. Target (optional)
  4. icon (optional)

Instead of passing a target as the third argument you can change/set the target using the $item->setTarget(MenuItem::TARGET_BLANK) method.

There are predefined targets to choose from set as constants inside the 'Braunstetter\MenuBundle\Items\MenuItem' class.

Setting targets

As shown above - the linkToUrl item comes with the possibility to set the target attribute by passing it as a third argument to the static method. This is useful because an extern/absolute Link often should be opened as a target="_blank" link. But if you want to change the target of any other link you can do this by using the setTarget method of any MenuItem implementing MenuItemInterface.

Here is a full example - and as you can see:

Custom menu items

You are not limited to use the build in menu types. You can just create a class with a few static methods in order to create your own menu-item Factory. Or just pass a new Braunstetter\MenuBundle\Items\Item directly:

Arguments:

  1. Label
  2. Icon (optional)
  3. Options (optional)

If you are using the default rendering blocks just $options['attr'], $options['linkAttr'] and $options['target'] have any impact on rendering results.

Passing the target as an option is actually the same as passing it directly to $options['linkAttr]. It is just a shortcut.

If you need to pass more options it is a good time for creating a custom MenuItem class extending Braunstetter\MenuBundle\Items\Item. This way you are able to create additional properties on your class and use the $options to fill them inside your constructor.

Breadcrumbs

The same menu defined inside the previous chapter can be used as a breadcrumb menu by just using the breadcrumbs() twig function.

A ready-to-be-styled markup gets rendered - divided by a caret.svg.

The main difference between the breadcrumbs() and the menu() function is, that breadcrumbs() just outputs a menu tree line, as soon as it contains some active route. Then the iteration stops and this active tree leaf gets printed.

Render menus by your own.

Sometimes you want to have complete control over the rendering of the menu with all the information needed in place. That's why you can use the menu_result() and the breadcrumbs_result() twig functions just the same way as described above. The only difference is, now you have the raw data instead of markup.

If you decide to go this way you may find it helpful to use the blocks defined in:

menu_blocks.html.twig and breadcrumb_menu_blocks.html.twig

Allow others to extend your menus with MenuEvents

If you build an ecosystem probably you would also like to give other users and / or bundles the option to extend or change your menus.

This is very easy and straightforward with menu events. After you injected the Symfony\Contracts\EventDispatcher\EventDispatcherInterface into the constructor of the menu class you are able to dispatch events:

Once you saved your menu inside a variable ($siteLinks in this case) you can create a new MenuEvent($siteLinks). Now you can dispatch events (e.g. 'app.main_menu')

The Braunstetter\MenuBundle\Events\MenuEvent holds the menu items and can prepend / append menu items. You can create an EventSubscriber:

This way it's very easy to build an extensible menu system for your software ecosystem.

Activate a menu item when it's not a direct children

Sometimes it's not just like every route is in a direct leaf of the parent, and we can just rely on these active trail. Then you need to tell your menu system 'somehow' to activate a seemingly unrelated menu item (and to activate its active trail).

Instead of going crazy with a custom Matcher you can just do that:

The Menu item matching this route will be active and all parents will be inside the active trail.

Note: selectedSubnavItem has to be inside the global twig scope - therefore define it in between your blocks or pass it as a variable from inside your controller.

The value of the selectedSubnavItem has to be equal to the handle of the MenuItem (snake cased label).


All versions of menu-bundle with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
symfony/framework-bundle Version ^6.0|^7.0
symfony/twig-bundle Version ^6.0|^7.0
symfony/yaml Version ^6.0|^7.0
symfony/string Version ^6.0|^7.0
webmozart/assert Version ^1.11
braunstetter/helper Version ^0.2.5
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package braunstetter/menu-bundle contains the following files

Loading the files please wait ....