1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

NodeChooser in Options

Discussion in 'XenForo Development Discussions' started by AndyB, Dec 2, 2015.

  1. AndyB

    AndyB Well-Known Member

    This is how I set up a Node Chooser in the Options page of my Similar Threads add-on.

    Options page

    pic001.jpg

    Editing the Options

    pic002.jpg

    The file structure

    pic003.jpg

    NodeChooser.php

    PHP:
    <?php

    abstract class Andy_SimilarThreads_Option_NodeChooser
    {
        public static function 
    renderSelect(XenForo_View $view$fieldPrefix, array $preparedOption$canEdit)
        {
            return 
    self::_render('andy_option_list_option_select'$view$fieldPrefix$preparedOption$canEdit);
        }

        public static function 
    getNodeOptions($selectedForum$includeRoot false$filter false)
        {
            
    /* @var $nodeModel XenForo_Model_Node */
            
    $nodeModel XenForo_Model::create('XenForo_Model_Node');

            
    $options $nodeModel->getNodeOptionsArray(
                
    $nodeModel->getAllNodes(),
                
    $selectedForum,
                
    $includeRoot
            
    );
        
            
    // define filter
            
    $filter 'Forum';

            if (
    $filter)
            {
                foreach (
    $options AS &$option)
                {
                    if (!empty(
    $option['node_type_id']) && $option['node_type_id'] != $filter)
                    {
                        
    $option['disabled'] = 'disabled';
                    }

                    unset(
    $option['node_type_id']);
                }
            }

            return 
    $options;
        }

        protected static function 
    _render($templateNameXenForo_View $view$fieldPrefix, array $preparedOption$canEdit)
        {
            
    $filter = isset($preparedOption['nodeFilter']) ? $preparedOption['nodeFilter'] : false;

            
    $preparedOption['formatParams'] = self::getNodeOptions(
                
    $preparedOption['option_value'],
                
    sprintf('(%s)', new XenForo_Phrase('unspecified')),
                
    $filter
            
    );

            return 
    XenForo_ViewAdmin_Helper_Option::renderOptionTemplateInternal(
                
    $templateName$view$fieldPrefix$preparedOption$canEdit
            
    );
        }
    }
    Admin Template -> andy_option_list_option_select

    Code:
    <xen:selectunit label="{$preparedOption.title}" name="{$fieldPrefix}[{$preparedOption.option_id}]" value="{xen:raw $preparedOption.option_value}"
    hint="{$preparedOption.hint}" size="10" multiple="true">
        <xen:options source="$formatParams" />
        <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>
    
     
    Last edited: Dec 2, 2015
    Lil.Tee and nrep like this.
  2. Hugilore111

    Hugilore111 Member

    Hi
    You can attach the installation files?
     
  3. James

    James Well-Known Member

    Similar Threads
     
    Hugilore111 and AndyB like this.
  4. nrep

    nrep Well-Known Member

    Thanks for posting this, I'm working on replacing some of my old manual selection code and using a forum chooser - so this is really handy :).
     

Share This Page