Cannot reproduce Server Error

Ferdinand

Well-known member
Affected version
2
I have had guests trigger the following error:
Code:
ErrorException: Template error: Method canViewMedia is not callable on the given object (XF\Entity\User) src/XF/Template/Templater.php:994
Generated by: Unknown account May 31, 2020
Stack trace
#0 [internal function]: XF\Template\Templater->handleTemplateError(512, 'Method canViewM...', '/home/edchatne/...', 994, Array)
#1 src/XF/Template/Templater.php(994): trigger_error('Method canViewM...', 512)
#2 internal_data/code_cache/navigation_cache.php(535): XF\Template\Templater->method(Object(XF\Entity\User), 'canViewMedia', Array)
#3 src/XF/Template/Templater.php(6660): XF\Pub\App->{closure}(Object(XF\Template\Templater), 'members', Array)
#4 src/XF/Pub/App.php(560): XF\Template\Templater->renderNavigationClosure(Object(Closure), 'members', Array)
#5 src/XF/Pub/App.php(513): XF\Pub\App->getNavigation(Array, 'members')
#6 src/XF/App.php(2001): XF\Pub\App->renderPageHtml('






    <div cl...', Array, Object(XF\Mvc\Reply\View), Object(XF\Mvc\Renderer\Html))
#7 src/XF/Mvc/Dispatcher.php(402): XF\App->renderPage('






    <div cl...', Object(XF\Mvc\Reply\View), Object(XF\Mvc\Renderer\Html))
#8 src/XF/Mvc/Dispatcher.php(58): XF\Mvc\Dispatcher->render(Object(XF\Mvc\Reply\View), 'html')
#9 src/XF/App.php(2190): XF\Mvc\Dispatcher->run()
#10 src/XF.php(391): XF\App->run()
#11 index.php(20): XF::runApp('XF\\Pub\\App')
#12 {main}
 
Is this still happening?

I'm not 100% certain but from the stack trace it appears as though you may have had some media specific links in your navigation tree under the "members" navigation item.

This isn't something we include by default so I assume it to be a custom one you added. If that's the case then if XFMG is ever disabled and you've gated the navigation item behind the $xf.visitor.canViewMedia() function then an error is expected. The default Media navigation entries are hidden when the add-on is disabled because they are assigned to the add-on so we know not to render them.

For something like this in custom navigation entries you could change the condition to:

Code:
is_addon_active('XFMG') AND $xf.visitor.canViewMedia()

Alternatively, this may have been triggered if you've ever had $config['enableListeners'] set to false in your src/config.php file. There isn't a workaround for that and an error being logged (not visible to users unless debug/development mode is enabled) is expected.
 
Back
Top Bottom