Problem/Motivation
With the update to 1.4 using the code that was supplied through a patch in
https://www.drupal.org/project/toc_filter/issues/2684629 →
, the TOC will now show up on every single page even if you uncheck that option in the TOC filter configuration.
The reason being is that the value for that variable is stored in the database as an integer, but the code on line 85 is checking to see if it's value is 0 AND a string using the === syntax:
if (variable_get('toc_filter_default_top', '0') === '0') {
As a result, this if statement only passes if you do not have the toc_filter_default_top variable saved in the database and it ends up using the default value passed to variable_get, which is a string. Once you save the config and it's put into the database, it's stored as an integer - the serialized value in the variable table shows "i:0;".
Steps to reproduce
Use the module, go to the configuration page and save the settings making sure that "Insert table of contents by default" is unchecked and save. If necessary, check it off, save, then uncheck to make sure it's saved in the database with a value of zero.
If you like, look in the variable table for "toc_filter_default_top" and see if the value is indeed stored as "i:0;". If it's not, then there may be something different about your environment than mine, but I was able to verify this on multiple environments.
Clear the caches, then go to any page that has headings that are set to be used for the TOC filter. Make sure you have NOT explicitly added a TOC to the page in the text filter to which it applies. The TOC should display regardless. Remember to flush all caches in between config changes.
Proposed resolution
Change the code on line 85 to the following:
if (variable_get('toc_filter_default_top', 0) == 0) {
Changing it to a double-equals is really the key, as then it doesn't really matter if it's a string or an integer. In this case there appears to be no real value in matching both the value AND the type.
Attached is an initial patch that fixes the issue.