1<?php
2
3namespace dokuwiki\plugin\dwedit;
4
5use dokuwiki\Menu\Item\AbstractItem;
6
7/**
8 * Class MenuItem
9 *
10 * @package dokuwiki\plugin\dwedit
11 */
12class MenuItem extends AbstractItem {
13
14    /** @var string do action for this plugin */
15    protected $type = 'dwedit';
16    private  $btn_name;
17
18    /** @var string icon file */
19   protected $svg = __DIR__ . '/edit_pencil.svg';
20
21    /**
22     * MenuItem constructor.
23     * @param string $btn_name (can be passed in from the  event handler)
24     */
25    public function __construct($btn_name = "") {
26        parent::__construct();
27        global $REV, $INFO;
28
29         if($btn_name)  {
30            $this->btn_name = $btn_name;
31         }
32
33        if($REV) $this->params['rev'] = $REV;
34
35        /*switching over to the native dw editor rquires two additional http paramters */
36        $this->params['mode'] = 'dwiki';
37        $this->params['fck_preview_mode'] = 'nil';
38        $this->params['do']="edit";
39        if ($INFO['perm'] < AUTH_EDIT) {   // use alternate icon if user does not have edit permission
40            $this->svg =  __DIR__ . '/book-open.svg';
41        }
42    }
43
44    /**
45     * Get label from plugin language file
46     *
47     * @return string
48     */
49    public function getLabel() {
50        if($this->btn_name) return $this->btn_name;
51    /*
52        if the button name has not been set up  in the constructor
53        you can get it now.
54        Note:    In the current case the name is guaranteed by
55        having been hard-coded in the event of a name not having been found
56     */
57
58         $hlp = plugin_load('action', 'dwedit');
59         $btn_name = $hlp->getLang('btn_dw_edit');
60		 return  $btn_name ?  $btn_name : "dwedit";
61
62
63    }
64}
65