ForumChooser

Cupara

Well-known member
Does the ForumChooser have a specific part of its code I can change then use in my own option file so it is not a drop down by possibly a spin box or something?

Thanks
 
Nevermind, geez I'm blind. I took another look and found the part that controls the display.
 
Right now I'm using the default forum chooser for my XenPorta... XenForo_Option_ForumChooser::renderOption

Have you figured out how to get it to allow multiple forum selection?
 
Yep sure have. I'm still figuring out how to get it to save the multiple options though. I will post up how I did it in a few.
 
Here is how I did it, yes it requires copying the ForumChooser file but in the end it saves a headache of altering the file by admins.

I created my own file and called it ForumChooser for now, the contents of the file is as follows:
PHP:
abstract class xPortal_Option_ForumChooser
{
    /**
     * Renders the forum chooser option.
     *
     * @param XenForo_View $view View object
     * @param string $fieldPrefix Prefix for the HTML form field name
     * @param array $preparedOption Prepared option info
     * @param boolean $canEdit True if an "edit" link should appear
     *
     * @return XenForo_Template_Abstract Template object
     */
    public static function renderOption(XenForo_View $view, $fieldPrefix, array $preparedOption, $canEdit)
    {
        $value = $preparedOption['option_value'];

        $editLink = $view->createTemplateObject('option_list_option_editlink', array(
            'preparedOption' => $preparedOption,
            'canEditOptionDefinition' => $canEdit
        ));

        /* @var $nodeModel XenForo_Model_Node */
        $nodeModel = XenForo_Model::create('XenForo_Model_Node');

        $forumOptions = $nodeModel->getNodeOptionsArray($nodeModel->getAllNodes(), $preparedOption['option_value'], '(unspecified)');

        return $view->createTemplateObject('option_list_option_select', array(
            'fieldPrefix' => $fieldPrefix,
            'listedFieldName' => $fieldPrefix . '_listed[]',
            'preparedOption' => $preparedOption,
            'formatParams' => $forumOptions,
            'editLink' => $editLink
        ));
    }
    public static function renderMultiple(XenForo_View $view, $fieldPrefix, array $preparedOption, $canEdit)
    {
        $value = $preparedOption['option_value'];

        $editLink = $view->createTemplateObject('option_list_option_editlink', array(
            'preparedOption' => $preparedOption,
            'canEditOptionDefinition' => $canEdit
        ));

        /* @var $nodeModel XenForo_Model_Node */
        $nodeModel = XenForo_Model::create('XenForo_Model_Node');

        $forumOptions = $nodeModel->getNodeOptionsArray($nodeModel->getAllNodes(), $preparedOption['option_value'], '(unspecified)');

        return $view->createTemplateObject('option_list_option_multiple', array(
            'fieldPrefix' => $fieldPrefix,
            'listedFieldName' => $fieldPrefix . '_listed[]',
            'preparedOption' => $preparedOption,
            'formatParams' => $forumOptions,
            'editLink' => $editLink
        ));
    }
}

Take note that "option_list_option_multiple" is the template that is called to display the option.

So next create an admin template with the following contents:
HTML:
<xen:selectunit label="{$preparedOption.title}" name="{$fieldPrefix}[{$preparedOption.option_id}]" multiple="{$preparedOption.option_value}"
hint="{$preparedOption.hint}" size="5">
    <xen:options source="$formatParams" />
    <xen:explain>{xen:raw $preparedOption.explain}</xen:explain>
    <xen:html>
        <input type="hidden" name="{$listedFieldName}" multiple="{$preparedOption.option_id}" />
        {xen:raw $editLink}
    </xen:html>
</xen:selectunit>

Take note that "value" has been changed to "multiple" which will add the multiple select box instead.

I'm still figuring out the DataType so it will save multiple choices.
 
For those who want to get this working:

The template:

Code:
<xen:selectunit size="10" multiple="true" label="{$preparedOption.title}" name="{$fieldPrefix}[{$preparedOption.option_id}]" value="{xen:raw $preparedOption.option_value}"
    hint="{$preparedOption.hint}">

   <xen:options source="$formatParams" selected="{$preparedOption.formatParams.selected}"/>
   <xen:explain>{xen:raw $preparedOption.explain}</xen:explain>
   <xen:html>
   <input type="hidden" name="{$listedFieldName}" value="{$preparedOption.option_id}" />
   {xen:raw $editLink}
   </xen:html>
</xen:selectunit>

You have to make sure you set:

DataType = Array
Array Sub-Options = *

And then:

Sem título.webp

The selected values are saved.
 
I think thre are a mistake to XenForo with php 5.4+. In the file library/XenForo/Model/Node.php, in 1255 there is this code line:
PHP:
                'selected' => (strval($selectedNodeId) === '0'),
that generates an error when the variable $selectedNodeId is an array of selected nodes, and the error occurs.
I changed this line to:
PHP:
                'selected' => (!$selectedNodeId ? '0' : '1'),
and works fine for me. I can use the 'All' selector in render options and all add-ons.

Salud2
 
Is this still a good tutorial to follow to create a multi select forum chooser option in 1.3.x? I'm trying to follow the steps but I get an error when creating the template in the steps above. It's saying 'selectunit" is an unknown tag.
 
Nevermind, I wasn't in the admin templates section. Still can't seem to get it to work though.
 
Last edited:
Top Bottom