Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zemd/symfony-menu
🥐 Very lightweight but powerful breadcrumbs builder for symfony
https://github.com/zemd/symfony-menu
breadcrumbs menu symfony symfony-component
Last synced: about 2 months ago
JSON representation
🥐 Very lightweight but powerful breadcrumbs builder for symfony
- Host: GitHub
- URL: https://github.com/zemd/symfony-menu
- Owner: zemd
- License: mit
- Archived: true
- Created: 2016-11-21T15:57:17.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2016-11-21T16:03:01.000Z (almost 8 years ago)
- Last Synced: 2024-09-25T05:32:46.708Z (about 2 months ago)
- Topics: breadcrumbs, menu, symfony, symfony-component
- Language: PHP
- Homepage:
- Size: 7.81 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Symfony Menu
> Very lightweight but powerful breadcrumbs builder for symfony
## Installation
```sh
composer require zemd/symfony-menu
```## Usage
This component build breadcrumb path leveraging standard symfony router. If you want to skip or modify some part of the
path feel free to use **@Breadcrumbs** annotation.For instance we have next controller:
```php
class MyController {
/**
* This route should be skipped from menu chain
*
* @Breadcrumbs(skip=true)
*/
public function myActionIwantToSkip() {}
/**
* This route should be in the root of menu tree
*
* @Route("/dashboard", name="dashboard")
* @Breadcrumbs(root=true)
*/
public function dashboardAction() {}
/**
* This route should be added automatically into menu chain
*
* @Route("/dashboard/graphs")
*/
public function viewMoreGraphsAction() {}
}
```Let's now share breadcrumbs into the view by using twig globals as example:
```php
class BreadcrumbsGlobalExtension extends \Twig_Extension implements Twig_Extension_GlobalsInterface
{
const NAME = 'zemd_breadcrumbs_extension';/** @var BreadCrumbsManager */
protected $breadcrumbsManager;public function __construct(BreadCrumbsManager $breadcrumbsManager) {
$this->breadcrumbsManager = $breadcrumbsManager;
}/**
* Returns the name of the extension.
*
* @return string The extension name
*/
public function getName() {
return self::NAME;
}public function getGlobals() {
return [
'zemd_breadcrumbs' => $this->breadcrumbsManager->getBreadcrumbs()
];
}
}
``````yml
services:
zemd.breadcrumbs_manager:
class: Zemd\Component\Menu\BreadCrumbsManager
arguments: ["@router", "@annotation_reader", "@request_stack"]
calls:
- [setContainer, ["@service_container"]]
zemd.breadcrumbs.twig_extension:
class: Path\To\Your\BreadcrumbsGlobalExtension
public: false
arguments: ["@zemd.breadcrumbs_manager"]
tags:
- { name: twig.extension }
zemd.router_checker.twig_extension:
class: Zemd\Component\Menu\Twig\Extension\RouteChecker
public: false
arguments: ["@request_stack", "@zemd.breadcrumbs_manager"]
tags:
- { name: twig.extension }
```Now we can show our menu in the header and style or translate menu items as we want:
```twig
{% for node in zemd_breadcrumbs %}
{% endfor %}```
## Advanced usage
// TODO: Example for generator
## License
Symfony Menu is released under the MIT license.
## Donate
[![](https://img.shields.io/badge/patreon-donate-yellow.svg)](https://www.patreon.com/red_rabbit)
[![](https://img.shields.io/badge/flattr-donate-yellow.svg)](https://flattr.com/profile/red_rabbit)