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