1<?php
2
3use ComboStrap\ExceptionNotFound;
4use ComboStrap\Toc;
5use ComboStrap\ExecutionContext;
6
7
8/**
9 *
10 * It will overwrite the toc data with our TOC if any
11 *
12 * This is just cosmetic
13 * Because this is almost never used
14 *
15 * It's needed only if the strap template is not used or in between upgrade
16 * in default mode meaning, never, ever but yeah.
17 *
18 */
19class action_plugin_combo_toc extends DokuWiki_Action_Plugin
20{
21
22
23    /**
24     *
25     * @param Doku_Event_Handler $controller
26     */
27    public function register(Doku_Event_Handler $controller)
28    {
29
30        // https://www.dokuwiki.org/devel:event:tpl_toc_render
31        $controller->register_hook('TPL_TOC_RENDER', 'BEFORE', $this, 'handle_toc');
32
33
34    }
35
36    /**
37     * Overwrite the TOC
38     * @param Doku_Event $event
39     * @param $param
40     */
41    public function handle_toc(Doku_Event &$event, $param)
42    {
43
44        $wikiReq = ExecutionContext::getActualOrCreateFromEnv();
45        if ($wikiReq->getExecutingAction() !== "show") {
46            // admin may also have toc
47            return;
48        }
49
50        try {
51            $toc = Toc::createForRequestedPage()
52                ->getValue();
53            $event->data = $toc;
54        } catch (ExceptionNotFound $e) {
55            return;
56        }
57
58
59    }
60
61
62}
63
64