{"id":18907565,"url":"https://github.com/cesurapp/pd-menu","last_synced_at":"2025-06-27T18:05:53.512Z","repository":{"id":62486352,"uuid":"119246258","full_name":"cesurapp/pd-menu","owner":"cesurapp","description":"Simple fast object-oriented menu maker for Symfony 5","archived":false,"fork":false,"pushed_at":"2021-05-06T23:33:09.000Z","size":60,"stargazers_count":15,"open_issues_count":1,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-28T16:42:45.280Z","etag":null,"topics":["component","menu","php","symfony-bundle","symfony4"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cesurapp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-01-28T09:52:34.000Z","updated_at":"2024-01-10T20:30:24.000Z","dependencies_parsed_at":"2022-11-02T10:15:33.230Z","dependency_job_id":null,"html_url":"https://github.com/cesurapp/pd-menu","commit_stats":null,"previous_names":["cesurapp/pd-menu","arrrray/pd-menu"],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cesurapp%2Fpd-menu","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cesurapp%2Fpd-menu/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cesurapp%2Fpd-menu/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cesurapp%2Fpd-menu/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cesurapp","download_url":"https://codeload.github.com/cesurapp/pd-menu/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249006527,"owners_count":21197290,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["component","menu","php","symfony-bundle","symfony4"],"created_at":"2024-11-08T09:22:10.465Z","updated_at":"2025-04-15T04:32:03.235Z","avatar_url":"https://github.com/cesurapp.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pdMenu Bundle\nSimple fast object-oriented menu maker for Symfony 5\n\n[![Packagist](https://img.shields.io/packagist/dt/appaydin/pd-menu.svg)](https://github.com/appaydin/pd-menu)\n[![Github Release](https://img.shields.io/github/release/appaydin/pd-menu.svg)](https://github.com/appaydin/pd-menu)\n[![license](https://img.shields.io/github/license/appaydin/pd-menu.svg)](https://github.com/appaydin/pd-menu)\n[![PHP from Packagist](https://img.shields.io/packagist/php-v/appaydin/pd-menu.svg)](https://github.com/appaydin/pd-menu)\n\nInstallation\n---\n\n#### Step 1: Download the Bundle\n\nOpen a command console, enter your project directory and execute the\nfollowing command to download the latest stable version of this bundle:\n\n```console\ncomposer require appaydin/pd-menu\n```\n\nThis command requires you to have Composer installed globally, as explained\nin the [installation chapter](https://getcomposer.org/doc/00-intro.md)\nof the Composer documentation.\n\n#### Step 2: Enable the Bundle\n\nWith Symfony 4, the package will be activated automatically. But if something goes wrong, you can install it manually.\n\nThen, enable the bundle by adding it to the list of registered bundles\nin the `config/bundles.php` file of your project:\n\n```php\n\u003c?php\n// config/bundles.php\n\nreturn [\n    //...\n    Pd\\MenuBundle\\PdMenuBundle::class =\u003e ['all' =\u003e true]\n];\n```\n\nCreate Your First menu\n---\n\n#### Step 1: Without Service\nYou can create menus without service. You can load the necessary parameters using `$options`\n\n```php\n\u003c?php\n// src/Menu/FirstMenu.php\n\nnamespace App\\Menu;\n\nuse Pd\\MenuBundle\\Builder\\ItemInterface;\nuse Pd\\MenuBundle\\Builder\\Menu;\n\nclass FirstMenu extends Menu\n{\n    /**\n     * Override\n     */\n    public function createMenu(array $options = []): ItemInterface\n    {\n        // Create Root Item\n        $menu = $this\n            -\u003ecreateRoot('settings_menu', true) // Create event is \"settings_menu.event\"\n            -\u003esetChildAttr(['data-parent' =\u003e 'admin_account_list']); // Add Parent Menu to Html Tag\n\n        // Create Menu Items\n        $menu-\u003eaddChild('nav_config_general', 1)\n            -\u003esetLabel('nav_config_general')\n            -\u003esetRoute('admin_settings_general')\n            -\u003esetLinkAttr(['class' =\u003e 'nav-item'])\n            -\u003esetRoles(['ADMIN_SETTINGS_GENERAL'])\n                // Contact\n                -\u003eaddChildParent('nav_config_contact', 5)\n                -\u003esetLabel('nav_config_contact')\n                -\u003esetRoute('admin_settings_contact')\n                -\u003esetLinkAttr(['class' =\u003e 'nav-item'])\n                -\u003esetRoles(['ADMIN_SETTINGS_CONTACT'])\n                // Email\n                -\u003eaddChildParent('nav_config_email', 10)\n                -\u003esetLabel('nav_config_email')\n                -\u003esetRoute('admin_settings_email')\n                -\u003esetLinkAttr(['class' =\u003e 'nav-item'])\n                -\u003esetRoles(['ADMIN_SETTINGS_EMAIL'])\n                // Template\n                -\u003eaddChildParent('nav_config_template')\n                -\u003esetLabel('nav_config_template')\n                -\u003esetRoute('admin_settings_template')\n                -\u003esetLinkAttr(['class' =\u003e 'nav-item'])\n                -\u003esetRoles(['ADMIN_SETTINGS_TEMPLATE'])\n                // Account\n                -\u003eaddChildParent('nav_config_user')\n                -\u003esetLabel('nav_config_user')\n                -\u003esetRoute('admin_settings_user')\n                -\u003esetLinkAttr(['class' =\u003e 'nav-item'])\n                -\u003esetRoles(['ADMIN_SETTINGS_USER']);\n\n        return $menu;\n    }\n}\n```\n\nRendering Menu\n---\nThe creation process is very simple. You can specify additional options.\n\n```twig\n{{ pd_menu_render('App\\\\Menu\\\\FirstMenu', {\n    'custom': 'variable or options'\n}) }}\n```\n\nYou can change the default options.\n```twig\n{{ pd_menu_render('App\\\\Menu\\\\FirstMenu', {\n    'template': '@PdMenu/Default/menu.html.twig',\n    'depth': null,\n    'currentClass': 'active',\n    'trans_domain': 'admin',\n    'iconTemplate' =\u003e '\u003ci class=\"material-icons\"\u003eitext\u003c/i\u003e'\n}) }}\n```\n\nYou can change the default options globally.\n\n```twig\nconfig/packages/pd_menu.yaml\n\npd_menu:\n    template: '@PdMenu/Default/menu.html.twig',\n    depth: null,\n    currentClass: active\n    trans_domain: admin,\n    iconTemplate: '\u003ci class=\"fa\u0026text\"\u003e\u003c/i\u003e'\n```\n\nCreate Menu Event \u0026 Event Listener\n---\n#### Step 1: Create Menu Event\nAll menus automatic events are generated. Example : \"menu_name.event\"\n\n#### Step 2: Create Menu Listener\nNow let's create a listener for the event.\n```php\n\u003c?php\n// src/Listener/MenuListener.php\n\nnamespace App\\Listener;\n\nuse Pd\\MenuBundle\\Event\\PdMenuEvent;\n\nclass MenuListener\n{\n    public function onCreate(PdMenuEvent $event)\n    {\n        // Get Menu Items\n        $menu = $event-\u003egetMenu();\n\n        // Add New Item\n        $menu-\u003eaddChild('demo_item', 5)\n            -\u003esetLabel('Home Page')\n            -\u003esetRoute('home_route');\n    }\n}\n```\nLet's create a service for the listener.\n```yaml\nApp\\Menu\\MenuListener:\n    tags:\n        - { name: kernel.event_listener, event: settings_menu.event, method: onCreate }\n```\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcesurapp%2Fpd-menu","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcesurapp%2Fpd-menu","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcesurapp%2Fpd-menu/lists"}