diff --git a/inc/Menu/AbstractMenu.php b/inc/Menu/AbstractMenu.php index 87ae6f5dc61e2398d62fefdfffc3f061806e2712..ce021ab64711f702166efa95e734200541e32a0c 100644 --- a/inc/Menu/AbstractMenu.php +++ b/inc/Menu/AbstractMenu.php @@ -11,7 +11,7 @@ use dokuwiki\Menu\Item\AbstractItem; * It contains convenience functions to display the menu in HTML, but template authors can also * just accesst the items via getItems() and create the HTML as however they see fit. */ -abstract class AbstractMenu { +abstract class AbstractMenu implements MenuInterface { /** @var string[] list of Item classes to load */ protected $types = array(); diff --git a/inc/Menu/MenuInterface.php b/inc/Menu/MenuInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..91dde9db6946faa27fcdd350cf2e45d332476c80 --- /dev/null +++ b/inc/Menu/MenuInterface.php @@ -0,0 +1,20 @@ +<?php + +namespace dokuwiki\Menu; + +use dokuwiki\Menu\Item\AbstractItem; + +/** + * Interface MenuInterface + * + * Defines what a Menu provides + */ +Interface MenuInterface { + + /** + * Get the list of action items in this menu + * + * @return AbstractItem[] + */ + public function getItems(); +} diff --git a/inc/Menu/MobileMenu.php b/inc/Menu/MobileMenu.php index 6fe98b35c338786108effbc71c4c1c48ce773b99..29e17d163942f026b75a087dfaed16db45a01558 100644 --- a/inc/Menu/MobileMenu.php +++ b/inc/Menu/MobileMenu.php @@ -11,14 +11,14 @@ use dokuwiki\Menu\Item\AbstractItem; * menus. This is a meta menu, aggregating the items from the other menus and offering a combined * view. The idea is to use this on mobile devices, thus the context is fixed to CTX_MOBILE */ -class MobileMenu { +class MobileMenu implements MenuInterface { /** - * Returns all items grouped + * Returns all items grouped by view * * @return AbstractItem[][] */ - public function getItems() { + public function getGroupedItems() { $pagemenu = new PageMenu(AbstractItem::CTX_MOBILE); $sitemenu = new SiteMenu(AbstractItem::CTX_MOBILE); $usermenu = new UserMenu(AbstractItem::CTX_MOBILE); @@ -30,6 +30,18 @@ class MobileMenu { ); } + /** + * Get all items in a flat array + * + * This returns the same format as AbstractMenu::getItems() + * + * @return AbstractItem[] + */ + public function getItems() { + $menu = $this->getGroupedItems(); + return call_user_func_array('array_merge', array_values($menu)); + } + /** * Print a dropdown menu with all DokuWiki actions * @@ -57,7 +69,7 @@ class MobileMenu { $html .= '<select name="do" class="edit quickselect" title="' . $lang['tools'] . '">'; $html .= '<option value="">' . $empty . '</option>'; - foreach($this->getItems() as $tools => $items) { + foreach($this->getGroupedItems() as $tools => $items) { $html .= '<optgroup label="' . $lang[$tools . '_tools'] . '">'; foreach($items as $item) { $params = $item->getParams();