PHP Error when I click on Preview

nocte - February 9, 2009 - 03:08
Project:Taxonomy Super Select
Version:6.x-1.0
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:needs review
Description

Hello,

When I have TSS enabled and I click on preview I get an PHP error:
Warning: Invalid argument supplied for foreach() in /var/www/web/html/site.tld/modules/taxonomy/taxonomy.module on line 70

Kind regards,
nocte

#1

fourteen40 - February 13, 2009 - 09:33

I'm getting the same error on a fresh install. Thanks

#2

acb - February 28, 2009 - 19:47

Add me as well; not on node-save, but node preview.

#3

neerjasoftwares - March 2, 2009 - 12:21

I'm also getting this error with drupal 6.9, i'm getting this error when click on preview node button so please help us to resolve this error.
Please do this on urgent basis.

#4

neerjasoftwares - March 3, 2009 - 15:16

I have used "theme_node_preview" into my theme template.php file and change some code in it and this error resolved.

Please use this code if it will solve your problem.

-----------------------

<?php
/* Overwrite theme_node_preview function*/

function (your-current-themename)_node_preview($node) {
 
$output = '<div class="preview">';
 
 
// My added code
 
if (!empty($node->taxonomy)) {
      foreach (
$node->taxonomy as $key => $term) {
     
// A 'Multiple select' and a 'Free tagging' field returns an array.
     
if (is_array($term)) {
        foreach (
$term as $tid) {
            if(
$tid < 1) continue;
           
$taxonomy[$tid] = $tid;
        }
      }
     
$node->taxonomy[$key] = $taxonomy;
    }
  }
 
// custom code ends here 

 
$preview_trimmed_version = FALSE;
 
// Do we need to preview trimmed version of post as well as full version?
 
if (isset($node->teaser) && isset($node->body)) {
   
$teaser = trim($node->teaser);
   
$body = trim(str_replace('<!--break-->', '', $node->body));

   
// Preview trimmed version if teaser and body will appear different;
    // also (edge case) if both teaser and body have been specified by the user
    // and are actually the same.
   
if ($teaser != $body || ($body && strpos($node->body, '<!--break-->') === 0)) {
     
$preview_trimmed_version = TRUE;
    }
  }

  if (
$preview_trimmed_version) {
   
drupal_set_message(t('The trimmed version of your post shows what your post looks like when promoted to the main page or when exported for syndication.<span class="no-js"> You can insert the delimiter "&lt;!--break--&gt;" (without the quotes) to fine-tune where your post gets split.</span>'));
   
$output .= '<h3>'. t('Preview trimmed version') .'</h3>';
   
$output .= node_view(drupal_clone($node), 1, FALSE, 0);
   
$output .= '<h3>'. t('Preview full version') .'</h3>';
   
$output .= node_view($node, 0, FALSE, 0);
  }
  else {
   
$output .= node_view($node, 0, FALSE, 0);
  }
 
$output .= "</div>\n";

  return
$output;
}

// ----------------------------------------------
?>

Please remember to remove site cache.

#5

Annakan - March 14, 2009 - 18:56

I can confirm the error on a completely fresh install.

Thanks for the previous hack but I hate to reproduce the whole preview logic just to add such specific code.

And I have a hard time understanding the CAUSE of the problem your hack solve.

It seems to lie in the way freetagings terms are not object in previews but my vocabulary as NO freetaging.

Is it possible to solve the problem at the MODULE level ?

And maybe give an explanation of the problem analysis "neerjasoftwares" did that would help somebody correct the problem at the MODULE level ?

why if($tid < 1) continue; for example ? what's special about negative tid or the zero one ?

thanks a lot for you time.

#6

eresanto - April 2, 2009 - 21:10

#7

thelostboy - May 11, 2009 - 11:34

subscribe

#8

Gekiboy - October 9, 2009 - 22:01

I had the same issue. Here's a patch I made to fix it for the 6-1 branch

AttachmentSize
taxonomy_super_select-371291.patch 1.1 KB

#9

dboulet - November 26, 2009 - 19:31
Component:Miscellaneous» Code
Status:active» needs review

Here's an alternative patch, taken from http://drupal.org/node/326614#comment-1866476.

AttachmentSize
taxonomy_super_select-DRUPAL-6--1_preview_fix2.patch 1.5 KB
 
 

Drupal is a registered trademark of Dries Buytaert.