Users can add bikes, parts, and tools to their inventory.
Provide listing pages to view their inventory.
Prevent non admins from viewing user inventories.
Link to user inventory from account menu.
Bikes, parts, tools secondary tabs.
Views Tabs
Views lets you set up local tasks, referred to as "menu tabs".
But it can't do secondary tasks yet.
- https://www.drupal.org/project/drupal/issues/2172307
- https://www.drupal.org/project/drupal/issues/2804195
- https://www.drupal.org/project/drupal/issues/2027043
- https://www.drupal.org/project/drupal/issues/2693069
But it can do the first part, add an Inventory tab to the user account.
- Create a view listing parts, tools, and bikes.
- Give it the url /user/%user/inventory.
- Set up a menu tab with Inventory as the title.
- (The selected menu/link does not seem to matter).
- Click on the My account link, and you should see an Inventory tab.
Views Local Tasks Module
This module lets you customize views page tabs further and allows secondary tabs.
- Configure the Inventory view display menu tab settings.
(This seems to be necessary when using the module)- Set parent to custom with entity.user.canonical.
- Add a view display with the url /user/%user/inventory/parts.
- Select menu tab.
- Check the box for local task only.
- Select the Inventory display as the parent.
- Add another view display with /user/%user/inventory/tools.
- Repeat the menu tab settings.
- You should now have an Inventory tab on the user display page, with Parts and Tools secondary tabs.
Inventory Menu Link
Drupal provides a "My account" in the user account menu, which routes to /user.
The response is provided by UserController::userPage(), which redirects to entity.user.canonical, with the current user's ID as the parameter.
This redirects to /user/1, which is handled by the user entity view.
We'll copy this method to provide an inventory link in the user account menu that redirects to /user/1/inventory.
- Use drush gen to create a controller and route.
- Set the route url to /user/inventory.
-
#retrograde_custom.routing.yml retrograde_custom.inventory: path: '/user/inventory' defaults: _title: 'Inventory' _controller: '\Drupal\retrograde_custom\Controller\RetrogradeCustomController::userInventory' requirements: _permission: 'access own inventory'
-
- Add a userInventory function to the controller.
-
#\Drupal\retrograde_custom\Controller\RetrogradeCustomController public function userInventory() { return $this->redirect('view.user_inventory.parts', ['user' => $this->currentUser()->id()]); }
-
- Clear the cache and visit /user/inventory. It should redirect to user/1/inventory.
You could add a menu link in the account menu for /user/inventory.
But this can also be provided in MODULE.links.menu.yml.
-
retrograde_custom.inventory: title: Inventory description: My inventory menu_name: account route_name: retrograde_custom.inventory weight: 1