xref: /plugin/struct/action/title.php (revision eafc109f41a4f149995a4d5aadb0fb0af66a7b9d)
1<?php
2/**
3 * DokuWiki Plugin struct (Action Component)
4 *
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 * @author  Andreas Gohr, Michael Große <dokuwiki@cosmocode.de>
7 */
8
9// must be run within Dokuwiki
10use dokuwiki\plugin\struct\meta\Title;
11
12if(!defined('DOKU_INC')) die();
13
14/**
15 * Class action_plugin_struct_title
16 *
17 * Saves the page title when meta data is saved
18 */
19class action_plugin_struct_title extends DokuWiki_Action_Plugin {
20
21    /**
22     * Registers a callback function for a given event
23     *
24     * @param Doku_Event_Handler $controller DokuWiki's event controller object
25     * @return void
26     */
27    public function register(Doku_Event_Handler $controller) {
28        $controller->register_hook('PARSER_METADATA_RENDER', 'AFTER', $this, 'handle_meta');
29    }
30
31    /**
32     * Store the page's title
33     *
34     * @param Doku_Event $event
35     * @param $param
36     */
37    public function handle_meta(Doku_Event $event, $param) {
38        $id = $event->data['current']['last_change']['id'];
39        $title = new Title($id);
40
41        if(!blank($event->data['current']['title'])) {
42            $title->setTitle($event->data['current']['title']);
43        } else {
44            $title->setTitle(null);
45        }
46    }
47
48}
49