2020-04-02 23:15:41 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace dokuwiki\plugin\childrenpages;
|
|
|
|
|
|
|
|
use dokuwiki\Menu\Item\AbstractItem;
|
|
|
|
|
|
|
|
class MenuItem extends AbstractItem {
|
|
|
|
/**
|
|
|
|
* Generate a menu item from a passed string
|
|
|
|
*
|
|
|
|
* @param string $type
|
2020-04-02 23:44:50 +00:00
|
|
|
* @param string $label
|
2020-04-02 23:15:41 +00:00
|
|
|
*/
|
2020-04-03 00:14:16 +00:00
|
|
|
public function __construct(string $type, string $label = '') {
|
2020-04-02 23:15:41 +00:00
|
|
|
$this->type = $type;
|
2020-04-03 00:14:16 +00:00
|
|
|
if ( empty($label) ) {
|
|
|
|
$label = ucfirst($type);
|
|
|
|
}
|
2020-04-02 23:44:50 +00:00
|
|
|
$this->label = $label;
|
2020-04-02 23:15:41 +00:00
|
|
|
parent::__construct();
|
2020-04-03 03:32:33 +00:00
|
|
|
$this->setTargetFromType();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the item target link from its type
|
|
|
|
*/
|
|
|
|
protected function setTargetFromType() : void {
|
|
|
|
global $INFO;
|
|
|
|
global $plugin_controller;
|
|
|
|
if ( ! $plugin_controller->isdisabled('translate') ) {
|
2020-04-03 00:46:35 +00:00
|
|
|
// If the "translate" plugin is activated, the language code should stay the top-level namespace
|
2020-04-03 03:32:33 +00:00
|
|
|
$translate_plugin =& $plugin_controller->load('helper', 'translate');
|
2020-04-03 00:46:35 +00:00
|
|
|
$language = $translate_plugin->getPageLanguage();
|
|
|
|
if ( $language !== null && preg_match("/^$language:/", $INFO['id']) ) {
|
|
|
|
$this->id = preg_replace(
|
|
|
|
"/^$language:/",
|
|
|
|
"$language:".$this->type.':',
|
|
|
|
$INFO['id']
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$this->id = $this->type.':'.$INFO['id'];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$this->id = $this->type.':'.$INFO['id'];
|
|
|
|
}
|
2020-04-02 23:52:49 +00:00
|
|
|
$this->params = [];
|
2020-04-02 23:15:41 +00:00
|
|
|
}
|
|
|
|
}
|