Only take action during the generation of the page menu

This commit is contained in:
vv221 2020-04-03 00:04:45 +02:00
parent 8bd362aa01
commit 4ca920f729

View file

@ -17,7 +17,7 @@ class action_plugin_tabpage extends DokuWiki_Action_Plugin {
* *
* @param Doku_Event_Handler $controller * @param Doku_Event_Handler $controller
*/ */
public function register(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, 'addMenuItem');
} }
@ -26,7 +26,7 @@ class action_plugin_tabpage extends DokuWiki_Action_Plugin {
* *
* @param Doku_Event $event * @param Doku_Event $event
*/ */
public function addMenuItem(Doku_Event $event) { public function addMenuItem(Doku_Event $event) : void {
// Check that this method has been called in the expected context // Check that this method has been called in the expected context
if ( $event->name !== 'MENU_ITEMS_ASSEMBLY' ) { if ( $event->name !== 'MENU_ITEMS_ASSEMBLY' ) {
$message = "Tabpage plugin error:"; $message = "Tabpage plugin error:";
@ -34,6 +34,10 @@ class action_plugin_tabpage extends DokuWiki_Action_Plugin {
$message .= ", but it has been called by \"$event->name\"."; $message .= ", but it has been called by \"$event->name\".";
throw new Exception($message); throw new Exception($message);
} }
// Only add content to the page menu
if ( $event->data['view'] !== 'page' ) {
return;
}
trigger_error('addMenuItem() not implemented in '.get_class($this), E_USER_WARNING); trigger_error('addMenuItem() not implemented in '.get_class($this), E_USER_WARNING);
} }
} }