The oro_customer_menu defines the menu items that would populate the Account section of the user menu.
So to create new customer menu you need to :
1. Create action and route for the menu item.
2. Add the menu item to see it on Account section.
And if you want to show a datagrid for your menu, it’s simple :
3. Create datagrid
4. Add the datagrid to your layout
Let’s Started!!
1. Create action and route
• Create Frontend Controller:
#src/Ibnab/Bundle/CustomerMenuBundle/Controller/Frontend/CustomerMenuController.php
<?php namespace Ibnab\Bundle\CustomerMenuBundle\Controller\Frontend; use Symfony\Component\Routing\Annotation\Route; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Oro\Bundle\LayoutBundle\Annotation\Layout; class CustomerMenuController extends AbstractController { /** * @Route("/", name="ibnab_menu_frontend_index") * @Layout(vars={"entity_class"}) * * @return array */ public function indexAction() { return ['entity_class' => YourEntity::class]; } }
• Create routing.yml file:
#src/Ibnab/Bundle/CustomerMenuBundle/Resources/config/oro/routing.yml
ibnab_menu_frontend: resource: "@IbnabCustomerMenuBundle/Controller/Frontend/CustomerMenuController.php" type: annotation prefix: /customer/new-menu options: frontend: true
2. Add the menu item on navigation.yml
• Create navigation.yml file:
#src/Ibnab/Bundle/CustomerMenuBundle/Resources/config/oro/navigation.yml
navigation: menu_config: items: ibnab_customer_frontend_customer_user_menu_index: label: 'ibnab.menu.frontend.new-menu.label' route: 'ibnab_menu_frontend_index' position: 80 tree: oro_customer_menu: scope_type: menu_frontend_visibility children: ibnab_customer_frontend_customer_user_menu_index: ~ titles: ibnab_menu_frontend_index: 'ibnab.menu.frontend.frontend_index_title'
3. Create the datagrid
• Create datagrids.yml file:
# src/Ibnab/Bundle/CustomerMenuBundle/Resources/config/oro/datagrids.yml
datagrids: ibnab-new-menu-frontend-grid: source: type: orm query: select: …. from: - { table: … , alias: i } columns: …. sorters: columns: …. options: frontend: true
4. Add the datagrid into layout.yml
# src/Ibnab/CustomerMenuBundle/Resources/views/layouts/default/imports/ibnab_menu_frontend_index_grid/layout.yml
layout: imports: - id: datagrid root: __root actions: - '@setOption': id: __datagrid optionName: grid_name optionValue: ibnab-new-menu-frontend-grid
• Import the datagrid
# src/Ibnab/CustomerMenuBundle/Resources/views/layouts/default/ibnab_menu_frontend_index/layout.yml
layout: imports: - id: ibnab_menu_frontend_index_grid root: page_content actions: - '@setOption': id: page_title optionName: defaultValue optionValue: 'ibnab.menu.frontend.entity_plural_label'
• Import the Account Section
# src/Ibnab/Bundle/CustomerMenuBundle/Resources/views/layouts/blank/ibnab_menu_frontend_index/layout.yml
layout: imports: - id: oro_customer_page actions: []
Done!
Comments