Active
Project:
Table of Contents
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
18 Aug 2011 at 19:23 UTC
Updated:
19 Aug 2011 at 15:30 UTC
We can simplify the module a lot by removing all the system arround the [toc] "token" and replace it with the real drupal token system http://api.drupal.org/api/drupal/includes--token.inc/7.
The module has some global like $_tableofcontents_block_processing.
I think we should not try to avoid a double toc. If the user add the block and the [toc] in the body it's is choice...
Comments
Comment #1
mdm commentedI'm playing with the idea of doing a major clean up of the 7.x code. I want to have a real TOC object with methods on it and get rid of a lot of the functions floating around the global namespace. One of the ideas I have is a TOC::$built boolean class variable to prevent multiple TOCs being generated for one page. I also want to create a TOC_Attributes class that abstracts away a lot of the various attributes, provides accessors/mutators, provides reasonable defaults, etc. Basically I'd like to keep things more organized and contained, avoid global variables, and abstract away a lot of the code that I feel clutters up the hook implementations.
Comment #2
gagarine commentedBut what I don't understand is why do you want to prevent multiple generation of toc?
Comment #3
AlexisWilke commentedgagarine,
The [toc] is a real token system in D6... 8-)
As for the "multiple generation," the D6 version let you output any number of TOCs, but (attempts) to prevents the multiple passes used to add the anchors around the headers. This is especially important when you make use of the numbering system of the TOC module (i.e. where 1., 2., 3., etc. is added in each header).
Otherwise, I do agree that the module could use some reorganization help.
Thank you.
Alexis
Comment #4
gagarine commentedthanks for the infos.
If we use only a filter (like the one we already have) to add the id to the headers we should not have this problem no?
Comment #5
AlexisWilke commentedgagarine,
In the Drupal 6.x version it could be called for several reasons:
1. Block being created
2. [toc] tag found
3. Automatic TOC because we detect more than 3 anchors
4. Automatic TOC because the node type requires it
Anyone of these could generate a call to the filter and thus process the anchors multiple times. Unfortunately, there isn't a clean way to know that did happen on the corresponding $text variable... so I used two heuristics, one was to check the $text and see whether a class="toc" existed and the other was to use a global variable to prevent a double insertion. The truth being that it still happens so the existing tests do not work right in all cases yet.
Thank you.
Alexis