1<?php
2
3use ComboStrap\TemplateForWebPage;
4use ComboStrap\PluginUtility;
5use ComboStrap\SlotSystem;
6use ComboStrap\WikiPath;
7use ComboStrap\ExceptionCompile;
8use ComboStrap\ExceptionNotFound;
9use ComboStrap\FileSystems;
10use ComboStrap\FetcherPage;
11use ComboStrap\TemplateSlot;
12use ComboStrap\LogUtility;
13use ComboStrap\MarkupPath;
14use ComboStrap\Site;
15
16/**
17 * When a slot/fragment
18 * is created,
19 * this action will write the default slot
20 * into the edit html section
21 */
22class action_plugin_combo_slottemplate extends DokuWiki_Action_Plugin
23{
24
25
26    const CANONICAL = "slot-template";
27
28    public function register(Doku_Event_Handler $controller)
29    {
30
31        $controller->register_hook('COMMON_PAGETPL_LOAD', 'BEFORE', $this, 'handle_new_slot', array());
32
33    }
34
35    public function handle_new_slot(Doku_Event $event, $param)
36    {
37
38
39        $id = $event->data['id'];
40        $page = MarkupPath::createMarkupFromId($id);
41        if (!$page->isSlot()) {
42            return;
43        }
44
45
46        try {
47            $pathName = $page->getLastNameWithoutExtension();
48        } catch (ExceptionNotFound $e) {
49            LogUtility::internalError("Should not happen as it's not the root", self::CANONICAL);
50            return;
51        }
52
53        $pageHeaderPath = TemplateSlot::createFromPathName($pathName)->getDefaultSlotContentPath();
54        if (!FileSystems::exists($pageHeaderPath)) {
55            return;
56        }
57        try {
58            $event->data["tpl"] = FileSystems::getContent($pageHeaderPath);
59            $event->data["doreplace"] = false;
60        } catch (ExceptionNotFound $e) {
61            // Should not happen
62            LogUtility::error("Internal Error", self::CANONICAL, $e);
63        }
64
65
66    }
67}
68
69
70
71