Correction of a bug printing a node inside another...

Hwangar - June 3, 2009 - 15:27
Project:Printer, e-mail and PDF versions
Version:6.x-1.7
Component:Code
Category:bug report
Priority:normal
Assigned:Hwangar
Status:closed
Description

after this title, I'll explain myself, imagine this case:

"you compose one node for viewing, and, as part of this node you put another one (via views, editing the node-XXX.tpl.php, etc), you'll get that the second one gets the "link parameters configuration" from the main one" -> mistake!!!

my concrete case: I'm using content_profile for configure complex profiles for users, and I want to print, below nodes, info of the profile... the node_type "profile" is configured to not show print or send to a friend links, buts mixes configuration from the main one

bug and correction:
in the three modules, there is code for check if the link must be enabled or not:

function print_link_allowed($args) {
  ...
  if (!empty($args['node'])) {
    // static $node_type = FALSE;

    // $node = $args['node'];
    // if ($node_type === FALSE) {
      // if (isset($node->type)) {
        // $node_type = $node->type;
      // }
      // else {
        // $node_type = '';
      // }
    // }
    $node_type = (isset($node->type)?$node->type:'');

you have the commented current version that saves in a static variable the node_type (even if you call it 1000 times), and my correction that gets the value each time

i recommend this for correction providing for me is a bug, and sure there will be more cases it'll fail

let me know if this was useful just to feel a bit prouder :P
Hwangar
Spain

#1

jcnventura - June 3, 2009 - 15:37
Status:active» postponed (maintainer needs more info)

That patch can't be right...

You're commenting out the $node var assignment, but later on you see if it is set?!

Can you provide the steps and simple node-XXX.tpl.php so that I can try to reproduce this?? The print_link_allowed does a lot of stuff that I would prefer could be done only once per page (that's why the static is there).

João

#2

Hwangar - June 3, 2009 - 15:51

Sorry!! you were fast!
I have just realised this is the code:

  if (!empty($args['node'])) {
    // static $node_type = FALSE;

    $node = $args['node'];
    // if ($node_type === FALSE) {
      // if (isset($node->type)) {
        // $node_type = $node->type;
      // }
      // else {
        // $node_type = '';
      // }
    // }
    $node_type = (isset($node->type)?$node->type:'');

I was too enthusiastic with commenting... and as the link disappeared I thought the job was done... :P

Tell me if it works

PD I have no problem to give you an extract of my template:

node-mytype.tpl.php

   ...
    <div class="content">
   
      <!-- BEGIN-CONTENT -->
      <table width="100%"><tr><td width="50%">
        <?php include "node-VO-chars.tpl.php"; // where I theme the fields of my node ?>
      </td><td width="50%">
        <?php include "node-VO-media.tpl.php"; // where I theme the image_field/media_field of the node, kinda media gallery ?>
      </td></tr>
      <tr><td colspan="2">
          <?php
            $account
= user_load($node->uid);
            if (!empty(
$account)):
         
?>

          <div id="vehicle-user">
            <h2 class="title">
              <div style="display: inline; vertical-align: top;">
                <div class="title-icon pngfix"><div class="title-icon2 pngfix"/></div>
                <div class="title-text">Usuario</div>
              </div>
            </h2> 
           
            <?php
            user_build_content
($account); 
            print
theme('user_profile', $account);
           
?>

           
            <a href="<?php print url('user/'.$node->uid.'/contact') ?>" id="contact">Contactar</a> 
            <?php popups_add_popups(array('#contact', '#contact'=>array('width'=>'400px'))); ?>
           
          </div>
          <?php endif; ?>
      </td>
      </table>
      <!-- END-CONTENT -->
   
    </div>
    ...

as you can see below the node I print my user profile, and part of it is a "content_profile node" that is rendered too, my configuration is set in that way I want print and mailto links for the main node but NOT for the profile node, and inside my profile were rendered with the node view process... with this correction all seems right

note: as I have read in the code it's the same in the three modules

by the way... thank you for your great effort, I hope this help you with this great module, keep your good work, mate!
greetings

Hwangar
Spain

#3

Hwangar - June 4, 2009 - 07:43
Status:postponed (maintainer needs more info)» active

#4

jcnventura - June 16, 2009 - 14:05
Status:active» needs review

Hi,

The correct code is the following:

    static $node_type = FALSE;

    $node = $args['node'];
    if (isset($node->type)) {
      $node_type = $node->type;
    }
    // Node

The static needs to be there in order to correctly identify the node type during the node's comments links rendering (since comments are not nodes, they don't have a node type).

However, comparing it to FALSE was completely useless, so I removed that part. Please try this and let me know how it worked for you.

João

AttachmentSize
print_nodetype.patch 572 bytes

#5

jcnventura - July 3, 2009 - 11:17
Status:needs review» fixed

I have committed the code anyway, as it seems harmless.

#6

Hwangar - July 8, 2009 - 14:34

I'm glad it had helped...
thx for your great work, man!

#7

System Message - July 22, 2009 - 14:40
Status:fixed» closed

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

 
 

Drupal is a registered trademark of Dries Buytaert.