https://github.com/cesurapp/pd-menu
Simple fast object-oriented menu maker for Symfony 5
https://github.com/cesurapp/pd-menu
component menu php symfony-bundle symfony4
Last synced: 12 months ago
JSON representation
Simple fast object-oriented menu maker for Symfony 5
- Host: GitHub
- URL: https://github.com/cesurapp/pd-menu
- Owner: cesurapp
- License: mit
- Created: 2018-01-28T09:52:34.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2021-05-06T23:33:09.000Z (about 5 years ago)
- Last Synced: 2025-03-28T16:42:45.280Z (about 1 year ago)
- Topics: component, menu, php, symfony-bundle, symfony4
- Language: PHP
- Homepage:
- Size: 58.6 KB
- Stars: 15
- Watchers: 3
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pdMenu Bundle
Simple fast object-oriented menu maker for Symfony 5
[](https://github.com/appaydin/pd-menu)
[](https://github.com/appaydin/pd-menu)
[](https://github.com/appaydin/pd-menu)
[](https://github.com/appaydin/pd-menu)
Installation
---
#### Step 1: Download the Bundle
Open a command console, enter your project directory and execute the
following command to download the latest stable version of this bundle:
```console
composer require appaydin/pd-menu
```
This command requires you to have Composer installed globally, as explained
in the [installation chapter](https://getcomposer.org/doc/00-intro.md)
of the Composer documentation.
#### Step 2: Enable the Bundle
With Symfony 4, the package will be activated automatically. But if something goes wrong, you can install it manually.
Then, enable the bundle by adding it to the list of registered bundles
in the `config/bundles.php` file of your project:
```php
['all' => true]
];
```
Create Your First menu
---
#### Step 1: Without Service
You can create menus without service. You can load the necessary parameters using `$options`
```php
createRoot('settings_menu', true) // Create event is "settings_menu.event"
->setChildAttr(['data-parent' => 'admin_account_list']); // Add Parent Menu to Html Tag
// Create Menu Items
$menu->addChild('nav_config_general', 1)
->setLabel('nav_config_general')
->setRoute('admin_settings_general')
->setLinkAttr(['class' => 'nav-item'])
->setRoles(['ADMIN_SETTINGS_GENERAL'])
// Contact
->addChildParent('nav_config_contact', 5)
->setLabel('nav_config_contact')
->setRoute('admin_settings_contact')
->setLinkAttr(['class' => 'nav-item'])
->setRoles(['ADMIN_SETTINGS_CONTACT'])
// Email
->addChildParent('nav_config_email', 10)
->setLabel('nav_config_email')
->setRoute('admin_settings_email')
->setLinkAttr(['class' => 'nav-item'])
->setRoles(['ADMIN_SETTINGS_EMAIL'])
// Template
->addChildParent('nav_config_template')
->setLabel('nav_config_template')
->setRoute('admin_settings_template')
->setLinkAttr(['class' => 'nav-item'])
->setRoles(['ADMIN_SETTINGS_TEMPLATE'])
// Account
->addChildParent('nav_config_user')
->setLabel('nav_config_user')
->setRoute('admin_settings_user')
->setLinkAttr(['class' => 'nav-item'])
->setRoles(['ADMIN_SETTINGS_USER']);
return $menu;
}
}
```
Rendering Menu
---
The creation process is very simple. You can specify additional options.
```twig
{{ pd_menu_render('App\\Menu\\FirstMenu', {
'custom': 'variable or options'
}) }}
```
You can change the default options.
```twig
{{ pd_menu_render('App\\Menu\\FirstMenu', {
'template': '@PdMenu/Default/menu.html.twig',
'depth': null,
'currentClass': 'active',
'trans_domain': 'admin',
'iconTemplate' => 'itext'
}) }}
```
You can change the default options globally.
```twig
config/packages/pd_menu.yaml
pd_menu:
template: '@PdMenu/Default/menu.html.twig',
depth: null,
currentClass: active
trans_domain: admin,
iconTemplate: ''
```
Create Menu Event & Event Listener
---
#### Step 1: Create Menu Event
All menus automatic events are generated. Example : "menu_name.event"
#### Step 2: Create Menu Listener
Now let's create a listener for the event.
```php
getMenu();
// Add New Item
$menu->addChild('demo_item', 5)
->setLabel('Home Page')
->setRoute('home_route');
}
}
```
Let's create a service for the listener.
```yaml
App\Menu\MenuListener:
tags:
- { name: kernel.event_listener, event: settings_menu.event, method: onCreate }
```