Okay, so I saw a new light
:bulb:
This way the amount of 'declarations' is minimized.
We will have to create all '*cp routes' ourselves and not through a
routing.yml
file.
Which should be better anyways, so we define the prefix (eg, '/admin', '/moderator', '/user').
We will have service declaration files per control panel.
services_menu_acp.yml
or
services_acp_menu.yml
Code: Select all
services:
acp.menu:
class: phpbb\di\service_collection
arguments: ['@service_container']
tags: [{ name: service_collection, tag: acp }]
acp_general:
tags: { name: acp }
class: \phpbb\cp\item
shared: false
arguments:
-
auth: acl_a
icon: cogs
route: acp_index
parent: ''
before: ''
acp_index:
tags: { name: acp }
class: \phpbb\cp\item
shared: false
arguments:
-
auth: acl_a_board
icon: home
route:
path: /index
defaults:
_controller: acp.main:main
page: 1
parent: acp_general
before: ''
pagination: 'page'
or
Code: Select all
services:
acp.menu:
class: phpbb\di\service_collection
arguments: ['@service_container']
tags: [{ name: service_collection, tag: acp }]
acp_general:
tags: { name: acp }
class: \phpbb\cp\item
shared: false
arguments:
- acl_a
- cogs
- acp_index
- ''
- ''
acp_index:
tags: { name: acp }
class: \phpbb\cp\item
shared: false
arguments:
- acl_a_board
- home
-
path: /index
defaults:
_controller: acp.main:main
page: 1
- acp_general
- ''
- 'page'
The first declarations, has a bit of a different
arguments
set up. But doing it like so, means there is only argument. An associated array. The benefit of this, is that the order does not matter and we have literal keys and only arguments have to be specified that are needed for that specific declaration.
The second declarations, use the 'regular' way of defining
arguments
. Downside of this is that if you want to specify the 8th argument, you are obliged to specify the first 7 aswell.
Now when the container is build, we can grab all the menu's. Iterate over the items and grab their routes. If the route is defined (in my above example, it is an array if a route should be created), we create a route with the item's name, eg
acp_index
, and the options defined in the array. That should be exactly the same someone would normally do in a
routing.yml
file.
Then if the
pagination
argument is set, it will also create a "pagination" route, eg
acp_index_pagination
. The value of the
pagination
argument, "page", is added to the path,
path: /index/{page}
and removed from the
defaults
array.
Now in the
(adm_)page_header()
function we run a new function:
build_cp_menu()
. The "building" as the menu's need to be globally available anyway - as per request of Hanakin. The adm_page_header will only create the acp menu, while page_header will create the ucp and mcp. The title can easily be created from
strtoupper(acp_index)
.
Then in a/the Symfony Routing Loader, we check which route is being used. If it's one created by the *cp menu's, we do two things: 1. check authentication, to see if the user is authorised to access these controllers. 2. Set the menu item and its parents to "active" for the template.
---
This means that there are two service declarations: The controller and the Menu item.
There is only one file handling the 'menu items', not all in a separate file.
The 'core' handles the language strings (titles) and routes.
The 'core' handles the authentication of the initial controllers and their menu's parents.