PHP Fatal error: Uncaught Error: Call to a member function getTemplateResource()

Hi,
I’m currently writing another plugin, which is a copy of an already working plugin that I created. This plugin’s main class checks if a specific page is being viewed and will display a custom template in its place. I have basically just copied the original plugin, renamed all relevant classes, etc… but this version is crashing where the other one works.

It appears that the template resource is being interpreted as NULL for some reason and I’m struggling to see why. (The template exists and is in the folder structure)

The error log shows the following 2 entries:

[Thu May 26 11:54:36.561242 2022] [php7:warn] [pid 10160:tid 1816] [client ::1:65419] PHP Warning: Declaration of RCVSKReviewerHubPluginHandler::index(array $args, Request $request): string should be compatible with PKPHandler::index($args, $request) in C:\\xampp\\htdocs\\ojs\\plugins\\generic\\rcvskReviewerHub\\RCVSKReviewerHubPluginHandler.inc.php on line 13 [Thu May 26 11:54:36.640944 2022] [php7:error] [pid 10160:tid 1816] [client ::1:65419] PHP Fatal error: Uncaught Error: Call to a member function getTemplateResource() on null in C:\\xampp\\htdocs\\ojs\\plugins\\generic\\rcvskReviewerHub\\RCVSKReviewerHubPluginHandler.inc.php:19\nStack trace:\n#0 C:\\xampp\\htdocs\\ojs\\lib\\pkp\\classes\\core\\PKPRouter.inc.php(395): RCVSKReviewerHubPluginHandler->index(Array, Object(Request))\n#1 C:\\xampp\\htdocs\\ojs\\lib\\pkp\\classes\\core\\PKPPageRouter.inc.php(255): PKPRouter->_authorizeInitializeAndCallRequest(Array, Object(Request), Array, false)\n#2 C:\\xampp\\htdocs\\ojs\\lib\\pkp\\classes\\core\\Dispatcher.inc.php(144): PKPPageRouter->route(Object(Request))\n#3 C:\\xampp\\htdocs\\ojs\\lib\\pkp\\classes\\core\\PKPApplication.inc.php(362): Dispatcher->dispatch(Object(Request))\n#4 C:\\xampp\\htdocs\\ojs\\index.php(68): PKPApplication->execute()\n#5 {main}\n thrown in C:\\xampp\\htdocs\\ojs\\plugins\\generic\\rcvskReviewerHub\\RCVSKReviewerHubPluginHandler.inc.php on line 19

The code in question is:-

import('classes.handler.Handler');
class RCVSKReviewerHubPluginHandler extends Handler {
	public function index(array $args, Request $request): string {
		$plugin = PluginRegistry::getPlugin('generic', 'RCVSKReviewerHubplugin');
    $templateMgr = TemplateManager::getManager($request);
    return $templateMgr->display($plugin->getTemplateResource('frontend/pages/reviewerhub.tpl'));
  }

  public function view($args, $request) {
		$plugin = PluginRegistry::getPlugin('generic', 'RCVSKReviewerHubplugin');
    $templateMgr = TemplateManager::getManager($request);
    return $templateMgr->display($plugin->getTemplateResource('frontend/pages/reviewerhub.tpl'));
  }
}

Line 19 is this one:

return $templateMgr->display($plugin->getTemplateResource('frontend/pages/reviewerhub.tpl'));

I have been through the code but cannot see why this one doesn’t work, and the plugin that it was copied from does.

I am using OJS 3.3.0.10 on XAMPP local dev server.

Has anyone experienced this error before?

Hi @Ant_Forshaw,

I’d double-check the name of the plugin; Looking at the other calls PluginRegistry::getPlugin(), the name of the plugin, passed as a second parameter, is in the lower case. It returns null if unable to find a plugin.

@Vitaliy Ahh! You star, thank you. Didn’t realise it had to be lowercase there.

I’ll remember that in future.

Thanks again.

1 Like

This topic was automatically closed after 2 days. New replies are no longer allowed.