I needed to exclude certain headers from the Table of Contents for a project, namely ones that were rendered via an 'accordion' paragraph. I added an optional setting to specify an XPath for headers to be excluded (that would otherwise pass under the other settings).
Patch attached achieves the basic functionality. Not sure what would happen for a malformed path.
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | toc_api-add_exclude_xpath_option-10.patch | 6.4 KB | smulvih2 |
Comments
Comment #2
bgilhome commentedComment #3
bgilhome commentedComment #4
bgilhome commentedNeed to use strict=TRUE for the in_array check on the $heading DOMElement. Updated patch atatched.
Comment #5
vladimirausLooks like we need to add hook_update to add new option for existing installations.
Comment #6
smulvih2#4 worked for me. Updated patch to fix a formatting issue and add an example xpath to field description to give users a good default for ignoring anything with a class of
toc-ignore.@vladimiraus, don't think we need a hook_update() for this. I added this patch to an existing install and it worked great; no change to functionality unless I manually add an xpath.
Comment #7
smulvih2Would be nice to get this included in a new release. I moved a site from drupal/tocify to this module because tocify relied on JS to build the TOC client-side and that had inherent accessibility issues. When doing a module comparison this module only lacked the ability to ignore certain DOM elements, which this patch fixes.
Comment #8
vladimirausThanks @smulvih2 for the contribution. Couple of things to fix:
hook_updatefor current installation to includeheader_exclude_xpathto all existing TOCsnew \DOMXPath($dom);tonew \DOMXPath($dom);Comment #9
smulvih2@vladimiraus, I don't think a hook_update() is needed here. Without a hook_update() the
header_exclude_xpathline is added to existing TOC config when a TOC is saved. Otherwise if theheader_exclude_xpathline is missing from TOC config it doesn't cause an issue. Theoptionsarray is protected so not sure how to update this, please advise.Also I tried removing the slash before
DOMXPath($dom);which is what I think you were trying to say in your last comment, but this causes an error, so working fine as is.Comment #10
smulvih2New patch with hook_update() to add header_exclude_xpath to all existing TOCs.
Comment #11
smulvih2@VladimirAus any chance you can review this and get into a new release? I'm using this patch on a few projects and its working great.
Comment #12
vladimirausThanks for your commit @smulvih2.
Give me few days...
Comment #13
liquidcms commentedAs I am using this functionality without this patch; safe to say this has been committed and this should be marked fixed/closed.
Also, wouldn't
//*[contains(@class,"toc-ignore")]//*have been a better default?Comment #14
smulvih2@liquidcms if you are using WxT this patch is included in the distro which is why it is working for you. Still waiting for this patch to be rolled into latest version of toc_api.
Comment #16
vladimirausThank you. Commited.
Comment #17
joseph.olstad@VladimirAus,
thank you!