Generate new menu items from a hardcoded list of children
This commit is contained in:
parent
a1c1c23c45
commit
eefa64ecb4
2 changed files with 47 additions and 3 deletions
18
MenuItem.php
Normal file
18
MenuItem.php
Normal file
|
@ -0,0 +1,18 @@
|
|||
<?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
|
||||
*/
|
||||
public function __construct(string $type) {
|
||||
$this->type = $type;
|
||||
parent::__construct();
|
||||
trigger_error("generating a menu item for type \"$this->type\" not implemented in ".get_class($this), E_USER_WARNING);
|
||||
}
|
||||
}
|
32
action.php
32
action.php
|
@ -11,6 +11,8 @@ if ( ! defined('DOKU_INC') ) {
|
|||
die();
|
||||
}
|
||||
|
||||
use dokuwiki\plugin\childrenpages\MenuItem;
|
||||
|
||||
class action_plugin_childrenpages extends DokuWiki_Action_Plugin {
|
||||
/**
|
||||
* Registers a callback function for a given event
|
||||
|
@ -18,7 +20,7 @@ class action_plugin_childrenpages extends DokuWiki_Action_Plugin {
|
|||
* @param Doku_Event_Handler $controller
|
||||
*/
|
||||
public function register(Doku_Event_Handler $controller) : void {
|
||||
$controller->register_hook('MENU_ITEMS_ASSEMBLY', 'AFTER', $this, 'addMenuItem');
|
||||
$controller->register_hook('MENU_ITEMS_ASSEMBLY', 'AFTER', $this, 'addMenuItems');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -26,7 +28,7 @@ class action_plugin_childrenpages extends DokuWiki_Action_Plugin {
|
|||
*
|
||||
* @param Doku_Event $event
|
||||
*/
|
||||
public function addMenuItem(Doku_Event $event) : void {
|
||||
public function addMenuItems(Doku_Event $event) : void {
|
||||
global $INFO;
|
||||
// Check that this method has been called in the expected context
|
||||
if ( $event->name !== 'MENU_ITEMS_ASSEMBLY' ) {
|
||||
|
@ -43,6 +45,30 @@ class action_plugin_childrenpages extends DokuWiki_Action_Plugin {
|
|||
if ( ! empty($INFO['namespace']) ) {
|
||||
return;
|
||||
}
|
||||
trigger_error('addMenuItem() not implemented in '.get_class($this), E_USER_WARNING);
|
||||
// Get the list of children pages
|
||||
$children = [ 'animation', 'gameplay', 'dev', 'talk' ];
|
||||
foreach ( $children as $child ) {
|
||||
$this->addMenuItem($event, $child);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new item to the page menu
|
||||
*
|
||||
* @param Doku_Event $event
|
||||
* @param string $child
|
||||
*/
|
||||
protected function addMenuItem(Doku_Event $event, string $child) {
|
||||
$item = $this->generateMenuItem($child);
|
||||
$event->data['items'][] = $item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a new menu item
|
||||
*
|
||||
* @param string $type
|
||||
*/
|
||||
protected function generateMenuItem(string $type) {
|
||||
return new MenuItem($type);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue