Skip to content
Snippets Groups Projects
Commit 31110e19 authored by Andreas Gohr's avatar Andreas Gohr
Browse files

introduce a MenuInterface

this helps tieing together the "normal" menus and the MobileMenu and
makes them both implement a getItems() method.
parent affc7ddf
No related branches found
No related tags found
No related merge requests found
......@@ -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();
......
<?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();
}
......@@ -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();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment