Control panel module system

General discussion of development ideas and the approaches taken in the 3.x branch of phpBB. The next feature release of phpBB 3 will be 3.3/Proteus.
Forum rules
Please do not post support questions regarding installing, updating, or upgrading phpBB 3.2.x. If you need support for phpBB 3.2.x please visit the 3.2.x Support Forum on phpbb.com.

If you have questions regarding writing extensions please post in Extension Writers Discussion to receive proper guidance from our staff and community.
User avatar
posey
Registered User
Posts: 29
Joined: Fri Dec 18, 2015 9:41 pm

Re: Control panel module system

Post by posey » Wed Apr 17, 2019 11:13 pm

I know, that's where we are clear on.
But how everything is defined. Cause we have three things:
- Routes (eg. /admin/index) that have to be defined
- Controllers (eg. phpbb.admin.controller) that have to be defined
- Lists for the *CP Menu (eg. General, Index, Settings, Board settings) that has to be created

And a valid point of cross reference is brought up. In simple terms, we want to get rid of the _info.php files to generate the list items.
But that is all fine and dandy, but we still need the associated language string, routes, structure (category, subcategory and children), authorization and by the looks of things icons. Not to mention we have to take extensions into consideration.

Nicofuma also mentioned wanting to create all 3 (routes, controller, list) from one declaration. I've tried various versions but non are suitable. Hence I am requesting an example of how the set up should look like.
Better known as mrgoldy.

CHItA
Development Team
Development Team
Posts: 160
Joined: Thu Mar 12, 2015 1:43 pm
Location: Budapest, Hungary

Re: Control panel module system

Post by CHItA » Mon May 06, 2019 10:37 am

I guess you could just start working on moving everything into controllers as it should be fairly straightforward and a big help (also a big task). That way you don't need to wait around for our feedback as we all seem to be uncertain how to properly handle the menu related code this time.

User avatar
posey
Registered User
Posts: 29
Joined: Fri Dec 18, 2015 9:41 pm

Re: Control panel module system

Post by posey » Mon May 13, 2019 8:45 pm

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.
Better known as mrgoldy.

User avatar
posey
Registered User
Posts: 29
Joined: Fri Dec 18, 2015 9:41 pm

Re: Control panel module system

Post by posey » Tue May 14, 2019 10:47 am

I quickly spoke with nicofuma, and he says it looks nice.
He also brought up a good point about the arguments, as symfony allows "named arguments".
This means prefixing them with $.

Code: Select all

    acp_general:
        tags: { name: acp }
        class: \phpbb\cp\item
        shared: false
        arguments:
            $auth: acl_a
            $icon: cogs
            $route: acp_index
            $parent: ''
            $before: ''
Then we can use those exact variables in the constructor, regardless of order(!).
public function __construct($auth = '', $before = '', $icon = '', $parent = '')
Better known as mrgoldy.

User avatar
3Di
Registered User
Posts: 754
Joined: Tue Nov 01, 2005 9:50 pm
Location: Milano (I) Frankfurt (D)
Contact:

Re: Control panel module system

Post by 3Di » Thu May 16, 2019 8:27 pm

posey wrote:
Tue May 14, 2019 10:47 am
Then we can use those exact variables in the constructor, regardless of order(!).
public function __construct($auth = '', $before = '', $icon = '', $parent = '')
That's interesting as well, indeed.
Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
Extensions, Scripts, MOD porting, Update/Upgrades
My development's activity º PhpStorm's proud user

User avatar
rxu
Registered User
Posts: 128
Joined: Tue Apr 04, 2006 4:28 pm
Contact:

Re: Control panel module system

Post by rxu » Sat May 18, 2019 7:05 pm

Just for the note: afaik this is the Symfony 3.3+ feature so can be suitable for phpBB 3.3+ only :)
Image

User avatar
posey
Registered User
Posts: 29
Joined: Fri Dec 18, 2015 9:41 pm

Re: Control panel module system

Post by posey » Mon May 20, 2019 9:55 am

Well, seeing this is targeted for 4.0 that should be fine.
I am currently coding against master branch and it's working as intended.
One thing to note though, is that the order in which arguments are defined in .yml does not matter, however if you want to define the Xth (say 4) parameter in the class' constructor, you have to define the first 3 aswell. Which is fine, just a note.
Better known as mrgoldy.

Post Reply