XF 2.0 Forum Chooser for single forum

AndyB

Well-known member
Hello,

In the Options page of one of my add-ons I can get a Forum Chooser to work properly but only for multiple forum selection. Here's the PHP code:

PHP:
<?php

namespace Andy\BirthdayThread\Option;

class ForumChooser extends \XF\Option\AbstractOption
{
    public static function renderSelect(\XF\Entity\Option $option, array $htmlParams)
    {   
        /** @var \XF\Repository\Node $nodeRepo */
        $nodeRepo = \XF::repository('XF:Node');

        $choices = $nodeRepo->getNodeOptionsData(true, 'Forum', 'option');
        $choices = array_map(function($v) {
            $v['label'] = \XF::escapeString($v['label']);
            return $v;
        }, $choices);

        $controlOptions = self::getControlOptions($option, $htmlParams);
        $controlOptions['multiple'] = true;

        $rowOptions = self::getRowOptions($option, $htmlParams);

        return self::getTemplater()->formSelectRow($controlOptions, $choices, $rowOptions);
    }   
}

When I change the following code:

$controlOptions['multiple'] = true;

from "true" to "false" I'm able to select just one forum from the drop down menu in the Options page, but I get the following error when I try to save the Options:

1505318269843.webp
 
Hmm ... \XF\Option\Forum::renderSelectMultiple seems to work just fine for multiple select, why do you want to create your own callback to handle the option?

If you want a single select use \XF\Option\Forum::renderSelect instead
forumSelectSingle.webp
 
Last edited:

Similar threads

Back
Top Bottom