XF 2.2 How to get the forum list into a widget option page

TheSkullKid

Member
Maybe there is someone who could tell me, on how I can get the forum list into the widget option page.
Do I need to fill the list of forum by myself?

Thanks
 

Brogan

XenForo moderator
Staff member
There isn't a predefined widget for that - it would require custom development, or manually populating the widget template.
 

TheSkullKid

Member
No I want to set the option of my widget, like extra field to lets say display the avatar in front of the user name. I also need to get the complete list of forums in there, so that the widget get only information of the selected one.

1626707644700.png

I found that code:

XML:
<xf:selectrow name="options[node_ids][]" value="{{ $options.node_ids ?: '' }}" multiple="multiple" size="7"
    label="{{ phrase('forum_limit') }}"
    explain="{{ phrase('only_include_threads_in_selected_forums') }}">

    <xf:option value="">{{ phrase('all_forums') }}</xf:option>
    <xf:foreach loop="$nodeTree.getFlattened(0)" value="$treeEntry">
        <xf:option value="{$treeEntry.record.node_id}" disabled="{{ $treeEntry.record.node_type_id != 'Forum' }}">
            {{ repeat('&nbsp;&nbsp;', $treeEntry.depth)|raw }} {$treeEntry.record.title}
        </xf:option>
    </xf:foreach>
</xf:selectrow>

But if I then open the widget option page, I get the following error:
  • Template admin:widget_def_options_tsk_mlam_widget: [E_USER_WARNING] Cannot call method getFlattened on a non-object (NULL) (src\XF\Template\Templater.php:1151)
 

beerForo

Well-known member
Maybe
 

TheSkullKid

Member
Maybe
This looks good, but I cannot download the addon from the referenced page. Account creation will be rejected all the time :(
 

TheSkullKid

Member
This code need to be placed into the Class you extended the AbstractWidget

PHP:
    protected function getNodeRepo()
    {
        return $this->repository('XF:Node');
    }
    
    protected function getDefaultTemplateParams($context)
    {
        $params = parent::getDefaultTemplateParams($context);
        if ($context == 'options')
        {
            $nodeRepo = $this->app->repository('XF:Node');
            $params['nodeTree'] = $nodeRepo->createNodeTree($nodeRepo->getFullNodeList());
        }
        return $params;
    }
 
Top