Multiselect usage in acp

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

Multiselect usage in acp

Post by GanstaZ » Thu Sep 27, 2018 8:41 am

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!)
"When answer lies in the question,.. question becomes redundant!"

User avatar
kasimi
Extension Customisations
Extension Customisations
Posts: 3292
Joined: Sat Sep 10, 2011 7:12 pm
Location: Germany
Contact:

Re: Multiselect usage in acp

Post by kasimi » Thu Sep 27, 2018 9:15 am

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: 565
Joined: Wed Oct 11, 2017 10:29 pm
Location: Zverse

Re: Multiselect usage in acp

Post by GanstaZ » Thu Sep 27, 2018 9:25 am

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?
"When answer lies in the question,.. question becomes redundant!"

User avatar
kasimi
Extension Customisations
Extension Customisations
Posts: 3292
Joined: Sat Sep 10, 2011 7:12 pm
Location: Germany
Contact:

Re: Multiselect usage in acp

Post by kasimi » Thu Sep 27, 2018 9:35 am

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
Registered User
Posts: 12983
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: Multiselect usage in acp

Post by 3Di » Thu Sep 27, 2018 9:51 am

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
Want to compensate me for my interest? Donate
Please PM me only to request paid works. Thx.
Extensions, Scripts, MOD porting, Update/Upgrades
My development's activity º PhpStorm's proud user

User avatar
Ger
Recognised Extension Developer
Posts: 1771
Joined: Wed Jan 02, 2008 7:35 pm
Location: 192.168.1.100
Contact:

Re: Multiselect usage in acp

Post by Ger » Thu Sep 27, 2018 10:20 am

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:
-Available for custom work-

User avatar
GanstaZ
Registered User
Posts: 565
Joined: Wed Oct 11, 2017 10:29 pm
Location: Zverse

Re: Multiselect usage in acp

Post by GanstaZ » Thu Sep 27, 2018 11:53 am

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!)
"When answer lies in the question,.. question becomes redundant!"

User avatar
3Di
Registered User
Posts: 12983
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: Multiselect usage in acp

Post by 3Di » Thu Sep 27, 2018 1:37 pm

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.
Want to compensate me for my interest? Donate
Please PM me only to request paid works. Thx.
Extensions, Scripts, MOD porting, Update/Upgrades
My development's activity º PhpStorm's proud user

User avatar
GanstaZ
Registered User
Posts: 565
Joined: Wed Oct 11, 2017 10:29 pm
Location: Zverse

Re: Multiselect usage in acp

Post by GanstaZ » Thu Sep 27, 2018 6:29 pm

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!
"When answer lies in the question,.. question becomes redundant!"

Post Reply

Return to “Extension Writers Discussion”

Who is online

Users browsing this forum: Neverlands and 5 guests