Page 1 of 1

Multiselect usage in acp

Posted: Thu Sep 27, 2018 8:41 am
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!)

Re: Multiselect usage in acp

Posted: Thu Sep 27, 2018 9:15 am
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>';
}

Re: Multiselect usage in acp

Posted: Thu Sep 27, 2018 9:25 am
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?

Re: Multiselect usage in acp

Posted: Thu Sep 27, 2018 9:35 am
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.

Re: Multiselect usage in acp

Posted: Thu Sep 27, 2018 9:51 am
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

Re: Multiselect usage in acp

Posted: Thu Sep 27, 2018 10:20 am
by Ger
Wouldn't it be more straightforward to add this as a radio select per forum, under "General forum settings"?

Re: Multiselect usage in acp

Posted: Thu Sep 27, 2018 11:53 am
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!)

Re: Multiselect usage in acp

Posted: Thu Sep 27, 2018 1:37 pm
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.

Re: Multiselect usage in acp

Posted: Thu Sep 27, 2018 6:29 pm
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!