Multiselect usage in acp

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
User avatar
GanstaZ
Registered User
Posts: 1187
Joined: Wed Oct 11, 2017 10:29 pm
Location: GZOverse

Multiselect usage in acp

Post by GanstaZ »

To put it short, I made a small extension, that modifies statistics output on index page. It is working without problems, but as pointed out by kasimi in development forum, it needs to be more user friendly. Did some research on this board about multiselect option, but making it to work in acp with events, at the moment is problematical for me. I am using a very simple working solution, but want to improve it, by replacing typing with multiselect. Any pointers or extension examples are welcome. Thank You!)
Usus est magister optimus! phpBB pre-Triton & latest php environment.
When answer lies in the question, question becomes redundant!
User avatar
kasimi
Former Team Member
Posts: 4900
Joined: Sat Sep 10, 2011 7:12 pm
Location: Germany
Contact:

Re: Multiselect usage in acp

Post by kasimi »

You can generate custom template code by setting the following keys in the display_vars option:

Code: Select all

'type'     => 'custom',
'function' => [$this, 'get_forum_select_template'],
Define the function that returns your option's custom template code:

Code: Select all

public function get_forum_select_template()
{
    return '<select name="esffs_exclude_ids">' . make_forum_select(...) . '</select>';
}
User avatar
GanstaZ
Registered User
Posts: 1187
Joined: Wed Oct 11, 2017 10:29 pm
Location: GZOverse

Re: Multiselect usage in acp

Post by GanstaZ »

I see, makes sense now).. thank you for the very useful info. By the way, is there a way, to move vars from one legend to another?
Usus est magister optimus! phpBB pre-Triton & latest php environment.
When answer lies in the question, question becomes redundant!
User avatar
kasimi
Former Team Member
Posts: 4900
Joined: Sat Sep 10, 2011 7:12 pm
Location: Germany
Contact:

Re: Multiselect usage in acp

Post by kasimi »

Your own var? Yes, have a look at phpbb_insert_config_array(): https://github.com/phpbb/phpbb/blob/rel ... ns_acp.php

Example:

Code: Select all

$display_vars['vars'] = phpbb_insert_config_array($display_vars['vars'], $my_config, ['after' => 'board_index_text']);
A core var? Probably, you might have to do some array_splice() juggling, but I wouldn't recommend it.
User avatar
3Di
I've Been Banned!
Posts: 17538
Joined: Mon Apr 04, 2005 11:09 pm
Location: I'm with Ukraine 🇺🇦
Name: Marco
Contact:

Re: Multiselect usage in acp

Post by 3Di »

An example using the same event as yours core.acp_board_config_edit_add

https://github.com/3D-I/h24as/blob/be0a ... p#L72-L108

in this case I have modified an existing native variable. Have a look at the comments.

------------------------------

Another use case, per forum basis and then doing a query to get the array.

Unique listener: https://github.com/phpBB-Studio/DateTop ... stener.php

And its template event: https://github.com/phpBB-Studio/DateTop ... ppend.html

The query/function: https://github.com/phpBB-Studio/DateTop ... #L210-L237
🆓 Free support for our extensions also provided here: phpBB Studio
🚀 Looking for a specific feature or alternative option? We will rock you!
Please PM me only to request paid works. Thx. Buy me a coffee -> Image
My development's activity º PhpStorm's proud user º Extensions, Scripts, MOD porting, Update/Upgrades
User avatar
Ger
Registered User
Posts: 2107
Joined: Wed Jan 02, 2008 7:35 pm
Location: 192.168.1.100
Contact:

Re: Multiselect usage in acp

Post by Ger »

Wouldn't it be more straightforward to add this as a radio select per forum, under "General forum settings"?
My extensions:
Simple CMS, Feed post bot, Avatar Resize, Modbreak, Magic OGP, Live topic update, Modern Quote, Quoted Where (GDPR) and Autoresponder.
Newest: FAQ manager for 3.2

Like my work? Buy me a coffee to keep it coming. :ugeek:

-Don't PM me for support-
User avatar
GanstaZ
Registered User
Posts: 1187
Joined: Wed Oct 11, 2017 10:29 pm
Location: GZOverse

Re: Multiselect usage in acp

Post by GanstaZ »

Much appreciated !Thank you both kasimi & 3Di for those explanations and examples!
@Ger - you may be right, but multiselect seems to be more friendly for the eye, then multi radio select. Thanks for the input!)
Usus est magister optimus! phpBB pre-Triton & latest php environment.
When answer lies in the question, question becomes redundant!
User avatar
3Di
I've Been Banned!
Posts: 17538
Joined: Mon Apr 04, 2005 11:09 pm
Location: I'm with Ukraine 🇺🇦
Name: Marco
Contact:

Re: Multiselect usage in acp

Post by 3Di »

Forgot to mention that if you are bound to use the option "per forum basis" as per the second example above, you should add the boolean column to the forums table within the migration.

https://github.com/phpBB-Studio/DateTop ... hp#L47-L50

if 0 (false) it does not affect the existing/newly created forums - it will be the next step as the admin's choice.
🆓 Free support for our extensions also provided here: phpBB Studio
🚀 Looking for a specific feature or alternative option? We will rock you!
Please PM me only to request paid works. Thx. Buy me a coffee -> Image
My development's activity º PhpStorm's proud user º Extensions, Scripts, MOD porting, Update/Upgrades
User avatar
GanstaZ
Registered User
Posts: 1187
Joined: Wed Oct 11, 2017 10:29 pm
Location: GZOverse

Re: Multiselect usage in acp

Post by GanstaZ »

Couldn't make it to work with multiselect, but it works with normal select when you modify custom method by adding config to hold $key.

Code: Select all

return '<select name="config[esffs_exclude_ids]">' . make_forum_select(...) . '</select>';
Now i see what you mean Ger, thanks to 3Di examples. I implemented second method for testing & it seems logical. Maybe it is the right way to do this. For the record: multiselect seems like mystery. I will keep that code somewhere for tests (maybe i can make it to work someday) and implement second method.)

Thanks kasimi, 3Di & Ger!
Usus est magister optimus! phpBB pre-Triton & latest php environment.
When answer lies in the question, question becomes redundant!
Post Reply

Return to “Extension Writers Discussion”