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;
|
2020-04-03 20:13:43 +00:00
|
|
|
$language = null;
|
|
|
|
// If one of the "translate" or "translation" plugins is activated, get the language code for the current page
|
2020-04-03 03:32:33 +00:00
|
|
|
if ( ! $plugin_controller->isdisabled('translate') ) {
|
|
|
|
$translate_plugin =& $plugin_controller->load('helper', 'translate');
|
2020-04-03 00:46:35 +00:00
|
|
|
$language = $translate_plugin->getPageLanguage();
|
2020-04-03 20:13:43 +00:00
|
|
|
} elseif ( ! $plugin_controller->isdisabled('translation') ) {
|
|
|
|
$translation_plugin =& $plugin_controller->load('helper', 'translation');
|
|
|
|
$language = $translation_plugin->getLangPart($INFO['id']);
|
|
|
|
}
|
|
|
|
// If the top level namespace is a language one, the children namespace should be inserted inside it
|
|
|
|
if ( $language !== null && preg_match("/^$language:/", $INFO['id']) ) {
|
|
|
|
$this->id = preg_replace(
|
|
|
|
"/^$language:/",
|
|
|
|
"$language:".$this->type.':',
|
|
|
|
$INFO['id']
|
|
|
|
);
|
2020-04-03 00:46:35 +00:00
|
|
|
} 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
|
|
|
}
|
|
|
|
}
|