[PHP] Identifier Config value

These requests for events in core phpBB have been merged into 3.1/Ascraeus and will be available with the next release.
User avatar
John P
Posts: 157
Joined: Sun Nov 04, 2012 7:39 am
Location: Netherlands
Contact:

[PHP] Identifier Config value

Post by John P »

Identifer: core.config
Location: acp_board.php
Parameters:
Explanation: If there is only one config value used by a extensions I would like the config value editable in acp board features instead of designing a whole page for editing this config value.

User avatar
John P
Posts: 157
Joined: Sun Nov 04, 2012 7:39 am
Location: Netherlands
Contact:

Re: [PHP] Identifier Config value

Post by John P »

Do I have to do more then only this?

User avatar
EXreaction
Registered User
Posts: 1555
Joined: Sat Sep 10, 2005 2:15 am

Re: [PHP] Identifier Config value

Post by EXreaction »

If you know some PHP I'd recommend trying to create the event yourself and then create a pull request for it.

User avatar
John P
Posts: 157
Joined: Sun Nov 04, 2012 7:39 am
Location: Netherlands
Contact:

Re: [PHP] Identifier Config value

Post by John P »

Yes I know some php and I tried this day but it's really hard. As it was in the old days just add a line in core it's now a lot more.
I added a listener, edit services.yml and edit acp_board.php but still no go.
I know it's executing the listener but don't find back the vars.
Is there more documentation available?

User avatar
EXreaction
Registered User
Posts: 1555
Joined: Sat Sep 10, 2005 2:15 am

Re: [PHP] Identifier Config value

Post by EXreaction »

You should not have to edit services.yml I would think. Why don't you submit what you've tried so far as a PR and we can take a look at it and help you with it.

User avatar
John P
Posts: 157
Joined: Sun Nov 04, 2012 7:39 am
Location: Netherlands
Contact:

Re: [PHP] Identifier Config value

Post by John P »

Thanks Ex, I have it working.
Still one wish I have, can I define at which position the config_name is injected in the feature list?

User avatar
EXreaction
Registered User
Posts: 1555
Joined: Sat Sep 10, 2005 2:15 am

Re: [PHP] Identifier Config value

Post by EXreaction »

What is your current code for it?

User avatar
John P
Posts: 157
Joined: Sun Nov 04, 2012 7:39 am
Location: Netherlands
Contact:

Re: [PHP] Identifier Config value

Post by John P »

Hi Ex,

It's working now but don't know if it can be better:
In acp_board.php under featurelist:

Code: Select all

                /**
                * Event to add config
                *
                * @event core.acp_config_edit_add
                * @since 3.1-A3
                */
                global $phpbb_dispatcher;
                $config_set_ext = $display_vars;
                $vars = array('config_set_ext');
                extract($phpbb_dispatcher->trigger_event('core.acp_config_edit_add', compact($vars)));
                $display_vars = $config_set_ext;
In listener.php in ext

Code: Select all

    public function load_config_on_setup($event)
    {
        $config_set_ext = $event['config_set_ext'];
        $config_set_vars = array_slice($config_set_ext['vars'], 0, 16, true);
        
        $config_set_vars['inactive_users_days'] = 
            array(
                'lang' => 'INACTIVE_USERS_DAYS',
                'validate' => 'int',
                'type'        => 'number:0:99',
                'explain'    => true
            );
        $config_set_vars += array_slice($config_set_ext['vars'], 16, count($config_set_ext['vars']) - 1, true);
        $event['config_set_ext'] = array('title' => $config_set_ext['title'], 'vars' => $config_set_vars);
    }
Thanks in advance

User avatar
EXreaction
Registered User
Posts: 1555
Joined: Sat Sep 10, 2005 2:15 am

Re: [PHP] Identifier Config value

Post by EXreaction »

That looks like a good start. There really isn't any need to rename the display_vars variable for the event.

Instead of putting the event within a specific mode, put the event after the switch ($mode) statement and send $mode and $display_vars to the listeners.

Using array_slice is about the only way to insert it at a specific location since the display vars is an associative array.

User avatar
John P
Posts: 157
Joined: Sun Nov 04, 2012 7:39 am
Location: Netherlands
Contact:

Re: [PHP] Identifier Config value

Post by John P »

Thanks Ex

acp_board

Code: Select all

        /**
        * Event to add config
        *
        * @event core.acp_config_edit_add
        * @since 3.1-A3
        */
        global $phpbb_dispatcher;
        $vars = array('display_vars', 'mode');
        extract($phpbb_dispatcher->trigger_event('core.acp_config_edit_add', compact($vars)));
 
Listener:

Code: Select all

    public function load_config_on_setup($event)
    {
        if ($event['mode'] == 'features')
        {
            $config_set_ext = $event['display_vars'];
            $config_set_vars = array_slice($config_set_ext['vars'], 0, 16, true);
            
            $config_set_vars['inactive_users_days'] = 
                array(
                    'lang' => 'INACTIVE_USERS_DAYS',
                    'validate' => 'int',
                    'type'        => 'number:0:99',
                    'explain'    => true
                );
            $config_set_vars += array_slice($config_set_ext['vars'], 16, count($config_set_ext['vars']) - 1, true);
            $event['display_vars'] = array('title' => $config_set_ext['title'], 'vars' => $config_set_vars);
        }
    }
 

Post Reply