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

Fixed  Possible Bug in XenForo_Option_NodeChooser

R

ragtek

Guest
#1
Check pls the method getNodeOptions

i'm trying to create a nodeselected checkbox
if i use this code
PHP:
        $forumOptions = XenForo_Option_NodeChooser::getNodeOptions(
            $value['node_id'],
            sprintf('(%s)', new XenForo_Phrase('unspecified')),
            'Forum'
        );
i'm getting this error.
PHP:
[SIZE=3][B]Template Errors: ragtek_fw_option_nodemultiselect[/B][/SIZE]

[LIST=1]
[*][I]Invalid argument supplied for foreach()[/I] in C:\xampp\htdocs\xenforo\library\XenForo\Template\Helper\Admin.php, line 1121
[*][I]Invalid argument supplied for foreach()[/I] in C:\xampp\htdocs\xenforo\library\XenForo\Template\Helper\Admin.php, line 1121
[*][I]Invalid argument supplied for foreach()[/I] in C:\xampp\htdocs\xenforo\library\XenForo\Template\Helper\Admin.php, line 1121
[*][I]Invalid argument supplied for foreach()[/I] in C:\xampp\htdocs\xenforo\library\XenForo\Template\Helper\Admin.php, line 1121
[*][I]Invalid argument supplied for foreach()[/I] in C:\xampp\htdocs\xenforo\library\XenForo\Template\Helper\Admin.php, line 1121
[*][I]Invalid argument supplied for foreach()[/I] in C:\xampp\htdocs\xenforo\library\XenForo\Template\Helper\Admin.php, line 1121
[*][I]Invalid argument supplied for foreach()[/I] in C:\xampp\htdocs\xenforo\library\XenForo\Template\Helper\Admin.php, line 1121
[*][I]Invalid argument supplied for foreach()[/I] in C:\xampp\htdocs\xenforo\library\XenForo\Template\Helper\Admin.php, line 1121
[*][I]Invalid argument supplied for foreach()[/I] in C:\xampp\htdocs\xenforo\library\XenForo\Template\Helper\Admin.php, line 1121
[*][I]Invalid argument supplied for foreach()[/I] in C:\xampp\htdocs\xenforo\library\XenForo\Template\Helper\Admin.php, line 1121
[/LIST]
problem is, that this check can't be run,
PHP:
    if (!empty($option['node_type_id']) && $option['node_type_id'] != $filter)
if includeroot is set to true in nodemodel getNodeOptionsArray

as you see here,
PHP:
    public function getNodeOptionsArray(array $nodes, $selectedNodeId = 0, $includeRoot = false)
    {
        $options = array();

        if ($includeRoot !== false)
        {
            $root = $this->getRootNode();

            $options[0] = array(
                'value' => 0,
                'label' => (is_string($includeRoot) === true ? $includeRoot : $root['title']),
                'selected' => (strval($selectedNodeId) === '0'),
                'depth' => 0,
            );
        }
the first element doesn't have a node_type_id and that's why the check is making troubles
 
R

ragtek

Guest
#2
ok this wasn't the problem

The problem was this admin template helper:
PHP:
    protected static function _getDisablerHtml(array $optionInfo, $optionId)
    {
        
        if ( !empty($optionInfo['disabled']))
        {
            $disablerHtml = "\n<ul id=\"{$optionId}_Disabler\">";
            foreach ($optionInfo['disabled'] AS  $disabled)
            {
                $disablerHtml .= "\n<li>$disabled</li>";
            }
            $disablerHtml .= "\n</ul>\n";
        }

        return $disablerHtml;
    }
it checks only, if $optionInfo['disabled'] is set, but not if it's an array (which is requested for the foreach)
This solved the problem:
PHP:
    protected static function _getDisablerHtml(array $optionInfo, $optionId)
    {
        $disablerHtml = '';
        if ( !empty($optionInfo['disabled']) AND is_array($optionInfo['disabled']))
        {
            $disablerHtml = "\n<ul id=\"{$optionId}_Disabler\">";
            foreach ($optionInfo['disabled'] AS  $disabled)
            {
                $disablerHtml .= "\n<li>$disabled</li>";
            }
            $disablerHtml .= "\n</ul>\n";
        }

        return $disablerHtml;
    }
Don't know if it's a xenforo bug