The following error message is shown when printing a page where e view has been included by EVA module and that view lists content with 'print' view mode.

Notice: Undefined index: #print_format in print_preprocess_node() (line 119 of /var/www/drupal/sites/all/modules/print/print.module).

I will shortly provide a patch to solve this problem, which simply checks if $variables['elements']['#print_format'] (line 119 of print.module) is set before trying to access it. I don't know if the array key not being set is a problem in another module or if Drupal allows it, but I think that simply checking if a key is set before accessing it can only be a safe improvement for Print module.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Norberto Ostallo’s picture

Status: Active » Needs review
FileSize
1.53 KB

The patch.

jcnventura’s picture

Status: Needs review » Needs work

Indeed, however if '#print_format' is not defined, we shouldn't be doing anything so the best would be to do:

if (($variables['elements']['#view_mode'] == 'print') && isset($variables['elements']['#print_format']))

Can you test using the above instead?

João

Norberto Ostallo’s picture

I just thought to leave the line
$variables['theme_hook_suggestions'][] = "node__print";
in order to enable the 'node__print' theme suggestion.
Anyway I confirm that it perfectly works also your way: indeed it was the first I tried and tested.

jcnventura’s picture

Basically, that node--print.tpl.php suggestion is there to allow you to use your own module-specific version of the node template.. The call to render the node content will include the '#print_format' variable if it comes from the print module.

I though the existing condition - checking if view mode is 'print' - was enough, but of course as I recycled the 'print' view mode from the core book module, you can actually be using the print build mode and not be using the module.

It's one extreme case: that you want to use book's HTML traversal while having the print module installed and you have created a node--print.tpl.php file - the content of the nodes of the HTML traversal would use the print template which would be unexpected.

jcnventura’s picture

Version: 7.x-2.x-dev » 7.x-1.1

And this applies to 7.x-1.x also...

Norberto Ostallo’s picture

I've never used the book module, but that's clear to me now. In this case what you were proposing works just as well.
Let me know if you need me to provide a patch for that too.

jcnventura’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.