trilbymedia / grav-plugin-page-toc

Grav TOC Plugin with new independent Anchor generation to compliment the existing Table-of-Contents support.
MIT License
14 stars 12 forks source link

traverseHeaderTags() must be of the type int, string given #17

Closed kees-closed closed 2 years ago

kees-closed commented 2 years ago

When upgrading from 3.0.0 to 3.1.0 I (only now) noticed double anchors on my website. This is because I also use the official plugin Anchors. Since I don't see the point in having this twice, but I do want to keep anchors elsewhere, I decided to disable them in the TOC plugin.

After saving those settings my site crashes with the error below:

"Argument 2 passed to Grav\Plugin\PageToc\MarkupFixer::traverseHeaderTags() must be of the type int, string given, called in /var/www/vhosts/example.com/www.example.com/user/plugins/page-toc/classes/MarkupFixer.php on line 57 ◀"

When restoring the anchor settings in the TOC plugin and refreshing the same error persisted. I now have the TOC disabled to keep my website functional.

In my user/config/plugins/page-toc.yaml is the following:

enabled: true
active: false
start: '2'
depth: '6'

Other than that, no custom changes enabled.

rhukster commented 2 years ago

Thanks I’ll take a look.

rhukster commented 2 years ago

Ok, its. simply because you have quotes around your start and depth which make them a string, when they should be an int.

should be:

enabled: true
active: false
start: 2
depth: 6

I've added a fix that will force conversion of string to int in this case, but you can easily fix it with the config above.

BTW, Page-TOC plugin can now effectively replace the anchors plugin. You don't need both. Page-TOC is actually better at it because its done in the content directly and cached, and is not done by the browser via JS.

kees-closed commented 2 years ago

Thanks for the quick fix! I use the admin panel to configure the plugins. I guess the slider in the admin panel for this plugin outputs strings instead of int's.

I'll keep an eye out for the update. Thanks again!

kees-closed commented 2 years ago

@rhukster is there by the way a sort of newsletter about new interesting plugins or when certain plugins replace others?

rhukster commented 2 years ago

There isn't but it's a good idea!

kees-closed commented 2 years ago

The issue persists, even when I remove those quotes from the start and depth values. Cleared the cache and removed the Anchor plugin (just in case). Still crashes with the same error.

You are running Grav v1.7.25

Yaml Linter
===========

User Configuration
------------------

 [OK] No YAML Linting issues with configuration                                                                         

Pages Frontmatter
-----------------

 [OK] No YAML Linting issues with pages                                                                                 

Page Blueprints
---------------

 [OK] No YAML Linting issues with blueprints                                                                            
rhukster commented 2 years ago

It won't show up as a YAML linting error as both string and integer values are valid in YAML, and the linting is just checking valid YAML and has no way to determine the expected type even if it was set.

I think you probably still have strings in the config file that it's using (maybe from an environment-based config). You can see this in the "config" tab of the debugbar.

Tomorrow i'll paste the 2 line code fix, don't have it handy right now.

kees-closed commented 2 years ago

I purged all configs and reinstalled it. That fixed it indeed. But after setting Start TOC headers and Start Anchor headers in the admin panel, ints are added to config/plugins/page-toc.yaml. Converting the type when loading the values works, but it might also be a good idea to fix this in the admin panel. It might prevent other plugins for crashing in the future.

marcocevoli commented 2 years ago

I also purged and reinstalled and the error persists.

rhukster commented 2 years ago

Just released v3.1.1 that should fix this.. You might need to save your options again in the admin to ensure they are saved as integers instead of strings.