I have this error when adding [toc] to a page. [toc] is never replaced by the expected outpout (I have activated the needed filter in the used text format)

Comments

paulinedupraz’s picture

A get the same issue when I restore the database with backup and migrate.

mdm’s picture

Assigned: Unassigned » mdm

I'm not able to reproduce the error, although I can see when using the text filter to enable TOC, it seems to have no effect. Could you please provide the [toc...] tag you're using in your content and the line number, if one appears, included in the error message? Thanks.

gagarine’s picture

StatusFileSize
new7.14 KB

I don't use the [toc tag but only the block. I had the filter to create the id on title and I think it's what is going wrong.

The problem is that _tableofcontents_replace_toc receive the format a full object (but is not the case when he came from the node_view).

Attached the backtrace when I clear the cache (without the arguments, it was to big and messy)

Here my *temporary* ugly workaround

function _tableofcontents_replace_toc($text, $format, $filter) {
  // we just don't have a way to pass that around our callbacks
  // (PHP is lacking on that one) but it is still a lot faster
  // that way.
  global $_tableofcontents_toc;
  global $_tableofcontents_block_toc;
  
// format give us an stdObject
  if(is_object($format)){
    $format = $format->format;
  }
....
lyly_double0’s picture

I just use [toc]. I will reinstall it in order to find the line number

lyly_double0’s picture

The error comes from line 636 of file tableofcontents.pages.inc

ciberconta’s picture

That's strange, I have the same error, but it only appears the first time that you visit website. Then, it disappears. Next day, it occurs again.

Note: I use the block.

michellezeedru’s picture

I am seeing this error as well. Always on the homepage, and sporadically on other pages. I am using TOC block. Appreciate any suggested workarounds or solutions. #3 gagarine - where did you put this code?

EDIT: I realize where gagarine added the fix in #3 (tableofcontents.pages.inc line 623). This seemed to resolve the error for me. Thanks!

pbfleetwood’s picture

Simply enabling the module causes this error on my site.

vacilando’s picture

Priority: Normal » Major

Same problem. Appears on node save. No TOC shown at all.

(No special settings. I need it to produce TOC automatically if the number of tags is high enough.)

EDIT: @gagarine's fix from #3 removes the error but the TOC still does not show, neither in automatic mode nor with the [toc] tag (I am using a page, not a block).

joel_osc’s picture

Status: Active » Needs review
StatusFileSize
new779 bytes

I think I have tracked it down, basically the function _tableofcontents_process is called in tableofcontents.module on link 231 and in the tableofcontents_block.module at line 33. The first calls it like:

$text = _tableofcontents_process($node->content['body'][0]['#markup'], $format);

where $format is an object and the second calls it with the string 'block':

$text = _tableofcontents_process(drupal_render($text['body']), 'block');

So to me the fix is to change line 231 of the tableofcontents.module to pass in $format->format. Patch file is attached.

foripepe’s picture

Duplications:
http://drupal.org/node/1441854
http://drupal.org/node/1660150

My patch. Needs review.

diff -r 676d810b9d18 sites/all/modules/contrib/tableofcontents/tableofcontents.pages.inc
--- a/sites/all/modules/contrib/tableofcontents/tableofcontents.pages.inc Mon Jul 23 14:16:38 2012 +0200
+++ b/sites/all/modules/contrib/tableofcontents/tableofcontents.pages.inc Mon Jul 23 14:41:18 2012 +0200
@@ -613,6 +613,10 @@
  * @return The $text with the [toc ...] replaced.
  */
 function _tableofcontents_replace_toc($text, $format, $filter) {
+  $format = (is_object($format) ? $format->format : $format);
+
   // we just don't have a way to pass that around our callbacks
   // (PHP is lacking on that one) but it is still a lot faster
   // that way.
davidneedham’s picture

#11 worked for me. Here's a .patch file for what was in the code tags for convenience.

md2’s picture

#11 worked for me

xaa’s picture

#11 works. thx

rfehren’s picture

This bug is still present in the Nov. 15 release. Please include the fix from #11 in the next release.