xref: /plugin/usersettings/MenuItem.php (revision 1ab406139ae52af26e6f9eaacaf1646e58521679)
1*1ab40613Stracker-user<?php
2*1ab40613Stracker-user
3*1ab40613Stracker-usernamespace dokuwiki\plugin\usersettings;
4*1ab40613Stracker-user
5*1ab40613Stracker-useruse dokuwiki\Menu\Item\AbstractItem;
6*1ab40613Stracker-user
7*1ab40613Stracker-user/**
8*1ab40613Stracker-user * User-menu item for the User Settings plugin.
9*1ab40613Stracker-user *
10*1ab40613Stracker-user * Links to the plugin's own settings page (do=usersettings). The action
11*1ab40613Stracker-user * component splices an instance of this in just before the "Update Profile"
12*1ab40613Stracker-user * item of the user menu.
13*1ab40613Stracker-user *
14*1ab40613Stracker-user * Like the core Profile item, this is only available to logged-in users —
15*1ab40613Stracker-user * the constructor throws for anonymous visitors, and the action component
16*1ab40613Stracker-user * skips the item when that happens.
17*1ab40613Stracker-user */
18*1ab40613Stracker-userclass MenuItem extends AbstractItem
19*1ab40613Stracker-user{
20*1ab40613Stracker-user    /**
21*1ab40613Stracker-user     * @throws \RuntimeException when the visitor is not logged in
22*1ab40613Stracker-user     */
23*1ab40613Stracker-user    public function __construct()
24*1ab40613Stracker-user    {
25*1ab40613Stracker-user        global $INPUT;
26*1ab40613Stracker-user
27*1ab40613Stracker-user        // Set the action type before the parent constructor runs: the parent
28*1ab40613Stracker-user        // derives params['do'] from $this->type, and AbstractItem::getType()
29*1ab40613Stracker-user        // only auto-fills it from the class name when it is still empty.
30*1ab40613Stracker-user        $this->type = 'usersettings';
31*1ab40613Stracker-user
32*1ab40613Stracker-user        parent::__construct();
33*1ab40613Stracker-user
34*1ab40613Stracker-user        if (!$INPUT->server->str('REMOTE_USER')) {
35*1ab40613Stracker-user            throw new \RuntimeException('user settings are only for logged in users');
36*1ab40613Stracker-user        }
37*1ab40613Stracker-user
38*1ab40613Stracker-user        // Label comes from the plugin's language file. Any plugin component
39*1ab40613Stracker-user        // exposes getLang(); the helper is the lightest one to borrow.
40*1ab40613Stracker-user        $helper = plugin_load('helper', 'usersettings');
41*1ab40613Stracker-user        if ($helper instanceof \helper_plugin_usersettings) {
42*1ab40613Stracker-user            $this->label = $helper->getLang('menu');
43*1ab40613Stracker-user        }
44*1ab40613Stracker-user
45*1ab40613Stracker-user        $this->svg = __DIR__ . '/images/usersettings.svg';
46*1ab40613Stracker-user    }
47*1ab40613Stracker-user}
48