. * * @file * @ingroup Skins */ namespace Skins\Chameleon\Components; use Sanitizer; use Skins\Chameleon\Menu\MenuFactory; /** * Class Menu * * @author Stephan Gambke * @since 1.0 * @ingroup Skins */ class Menu extends Component { /** * Builds the HTML code for this component * * @return String the HTML code */ public function getHtml() { if ( $this->getDomElement() === null ) { return ''; } $menu = $this->getMenu(); $menu->setMenuItemFormatter( function ( $href, $text, $depth, $subitems ) { $href = Sanitizer::cleanUrl( $href ); $text = htmlspecialchars( $text ); if ( $depth === 1 && !empty( $subitems ) ) { return "
  • $text$subitems
  • "; } else { return "
  • $text$subitems
  • "; } } ); $menu->setItemListFormatter( function ( $rawItemsHtml, $depth ) { if ( $depth === 0 ) { return $rawItemsHtml; } elseif ( $depth === 1 ) { return ""; } else { return ""; } } ); return $menu->getHtml(); } /** * @return \Skins\Chameleon\Menu\Menu */ public function getMenu() { $domElement = $this->getDomElement(); $msgKey = $domElement->getAttribute( 'message' ); $menuFactory = new MenuFactory(); if ( empty( $msgKey ) ) { return $menuFactory->getMenuFromMessageText( $domElement->textContent ); } else { return $menuFactory->getMenuFromMessage( $msgKey ); } } }