dokuwiki-plugin-childrenpages/MenuItem.php

48 lines
1.2 KiB
PHP

<?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
* @param string $label
*/
public function __construct(string $type, string $label = '') {
$this->type = $type;
if ( empty($label) ) {
$label = ucfirst($type);
}
$this->label = $label;
parent::__construct();
$this->setTargetFromType();
}
/**
* Set the item target link from its type
*/
protected function setTargetFromType() : void {
global $INFO;
global $plugin_controller;
if ( ! $plugin_controller->isdisabled('translate') ) {
// If the "translate" plugin is activated, the language code should stay the top-level namespace
$translate_plugin =& $plugin_controller->load('helper', 'translate');
$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'];
}
$this->params = [];
}
}