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

Fixed Code error in XenForo/Model/Node.php with render options in php 5.4 or greater

lms

Well-known member
#1
When you try to use a custom renderOptions in ACP, it's get an error so:
To add more information, this is what was in XenForo's error logs

Error Info
PHP:
ErrorException: Array to string conversion - library/XenForo/Model/Node.php:1255
Generated By: Adam, 6 minutes ago
Stack Trace

PHP:
#0 [internal function]: XenForo_Application::handlePhpError(8, 'Array to string...', '/home/sociall1/...', 1255, Array)
#1 /home/sociall1/public_html/forums/library/XenForo/Model/Node.php(1255): strval(Array)
#2 /home/sociall1/public_html/forums/library/MasterForums/Option/ForumChooser.php(18): XenForo_Model_Node->getNodeOptionsArray(Array, Array, '(unspecified)')
#3 [internal function]: MasterForums_Option_ForumChooser::renderOption(Object(XenForo_ViewAdmin_Option_ListOptions), 'options', Array, false)
#4 /home/sociall1/public_html/forums/library/XenForo/ViewAdmin/Helper/Option.php(327): call_user_func(Array, Object(XenForo_ViewAdmin_Option_ListOptions), 'options', Array, false)
#5 /home/sociall1/public_html/forums/library/XenForo/ViewAdmin/Helper/Option.php(71): XenForo_ViewAdmin_Helper_Option::_renderCallbackOptionHtml(Object(XenForo_ViewAdmin_Option_ListOptions), 'options', Array, false)
#6 /home/sociall1/public_html/forums/library/XenForo/ViewAdmin/Helper/Option.php(33): XenForo_ViewAdmin_Helper_Option::renderPreparedOptionHtml(Object(XenForo_ViewAdmin_Option_ListOptions), Array, false, 'options')
#7 /home/sociall1/public_html/forums/library/XenForo/ViewAdmin/Option/ListOptions.php(30): XenForo_ViewAdmin_Helper_Option::renderPreparedOptionsHtml(Object(XenForo_ViewAdmin_Option_ListOptions), Array, false)
#8 /home/sociall1/public_html/forums/library/XenForo/ViewRenderer/Abstract.php(215): XenForo_ViewAdmin_Option_ListOptions->renderHtml()
#9 /home/sociall1/public_html/forums/library/XenForo/ViewRenderer/HtmlAdmin.php(63): XenForo_ViewRenderer_Abstract->renderViewObject('XenForo_ViewAdm...', 'Html', Array, 'option_list')
#10 /home/sociall1/public_html/forums/library/XenForo/FrontController.php(533): XenForo_ViewRenderer_HtmlAdmin->renderView('XenForo_ViewAdm...', Array, 'option_list', NULL)
#11 /home/sociall1/public_html/forums/library/XenForo/FrontController.php(156): XenForo_FrontController->renderView(Object(XenForo_ControllerResponse_View), Object(XenForo_ViewRenderer_HtmlAdmin), Array)
#12 /home/sociall1/public_html/forums/admin.php(13): XenForo_FrontController->run()
#13 {main}
Request State

PHP:
array(3) {
  ["url"] => string(75) "http://www.sociallyuncensored.eu/forums/admin.php?options/list/MasterForums"
  ["_GET"] => array(1) {
    ["options/list/MasterForums"] => string(0) ""
  }
  ["_POST"] => array(0) {
  }
}
I think it's 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 ? $selectedNodeId : 0),
and works fine for me. I can use the 'All' selector in render options and all add-ons.

Salud2
 

Mike

XenForo developer
Staff member
#3
That's not really the correct fix so I've done a different one to prevent the error, but note that $selectedNodeId is expected to be an integer, so passing an array in isn't documented behavior.