Get info about displayed issue in plugin

Describe the issue or problem
In a plugin, I want to get information about the currently displayed issue. When I call one of the public member functions of the Issue object, I get a fatal PHP error. Why? What is wrong?

Steps I took leading up to the issue
I have stripped down my plugin to the bare minimum. I use the following register function:

  public function register($category, $path, $mainContextId = NULL) {

    // Register the plugin even when it is not enabled
    $success = parent::register($category, $path, $mainContextId);

    if ($success && $this->getEnabled($mainContextId)) {
      HookRegistry::register('Templates::Common::Footer::PageFooter', array(&$this, 'addSpecialIssueArticles'));
    }
    return $success;
  }

The function “addSpecialIssueArticles” is as follows:

  function addSpecialIssueArticles($hookName, $params) {
    $templateMgr =& $params[1];
    $output =& $params[2];
    $issue = $templateMgr->get_template_vars('issue');
    echo("<pre>");
    var_dump($issue);
    echo("</pre>"); 
    $descr = $issue->getLocalizedDescription();  
  }

The last line generates a fatal PHP error:

[13-Sep-2023 09:07:19 UTC] PHP Fatal error:  Uncaught Error: Call to a member function getLocalizedDescription() on null in /var/www/html/ojs_test_3.3.0-14/plugins/generic/specialIssueTST/SpecialIssueTST.i
nc.php:37
Stack trace:
#0 /var/www/html/ojs_test_3.3.0-14/lib/pkp/classes/plugins/HookRegistry.inc.php(107): SpecialIssueTSTPlugin->addSpecialIssueArticles('Templates::Comm...', Array)
#1 /var/www/html/ojs_test_3.3.0-14/lib/pkp/classes/template/PKPTemplateManager.inc.php(1527): HookRegistry::call('Templates::Comm...', Array)
#2 /var/www/html/ojs_test_3.3.0-14/cache/t_compile/25bcbc63bc70e004505931d447fb4131f159a9b2^4dffb64063bb972c37e05619a2ccd9d0ea7473ac_0.app.frontendcomponentsfooter..php(70): PKPTemplateManager->smartyCallH
ook(Array, Object(Smarty_Internal_Template))
#3 /var/www/html/ojs_test_3.3.0-14/lib/pkp/lib/vendor/smarty/smarty/libs/sysplugins/smarty_template_resource_base.php(123): content_64637002a791a1_09056910(Object(Smarty_Internal_Template))
#4 /var/www/html/ojs_test_3.3.0-14/lib/pkp/lib/vendor/smarty/smarty/libs/sysplugins/smarty_templa in /var/www/html/ojs_test_3.3.0-14/plugins/generic/specialIssueTST/SpecialIssueTST.inc.php on line 37

What application are you using?
I am using OJS 3.3.0.14

Additional information

The var_dump produces the following output:

object(Issue)#255 (6) {
  ["_data"]=>
  array(16) {
    ["id"]=>
    int(22)
    ["journalId"]=>
    int(1)
    ["volume"]=>
    int(7)
    ["number"]=>
    string(1) "1"
    ["year"]=>
    int(2020)
    ["published"]=>
    int(1)
    ["current"]=>
    int(1)
    ["datePublished"]=>
    string(19) "2020-03-09 14:20:04"
    ["lastModified"]=>
    string(19) "2020-03-09 14:20:04"
    ["accessStatus"]=>
    int(1)
    ["showVolume"]=>
    int(1)
    ["showNumber"]=>
    int(1)
    ["showYear"]=>
    int(1)
    ["showTitle"]=>
    int(0)
    ["description"]=>
    array(1) {
      ["en_US"]=>
      string(0) ""
    }
    ["title"]=>
    array(1) {
      ["en_US"]=>
      string(0) ""
    }
  }
  ["_hasLoadableAdapters"]=>
  bool(false)
  ["_metadataExtractionAdapters"]=>
  array(0) {
  }
  ["_extractionAdaptersLoaded"]=>
  bool(false)
  ["_metadataInjectionAdapters"]=>
  array(0) {
  }
  ["_injectionAdaptersLoaded"]=>
  bool(false)
}

Hi @gunthermaier,

I think there’s something more going on than can be explained by what you’ve posted; if the var_dump works, then $issue->getLocalizedDescription() should work as well.

Note that the issue template variable will legitimately be null if the issue hasn’t yet been published yet (i.e. if you’re previewing the article).

Regards,
Alec Smecher
Public Knowledge Project Team