mediawiki-skins-MinervaNeue/includes/Menu/User/UserMenuDirector.php
Jon Robson 6e297a7a9b [Refactor] Use core definitions for personal menu icons
Rather than hardcoding the icons for all our menu items
let's use the definitions in core.

This also makes it easier for us to deprecate the
MobileMenu hook in future.

Rejoice at all the code this removed!

Bug: T291568
Change-Id: I69b5ca13aee018982a5ea28677d4a37e663235d4
2022-01-19 00:33:16 +00:00

76 lines
2.3 KiB
PHP

<?php
/**
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* @file
*/
namespace MediaWiki\Minerva\Menu\User;
use MessageLocalizer;
use MinervaUI;
use TemplateParser;
/**
* Director responsible for building the user menu.
*/
final class UserMenuDirector {
/**
* @var IUserMenuBuilder
*/
private $builder;
/**
* @var MessageLocalizer
*/
private $localizer;
/**
* @param IUserMenuBuilder $builder
* @param MessageLocalizer $localizer
*/
public function __construct( IUserMenuBuilder $builder, MessageLocalizer $localizer ) {
$this->builder = $builder;
$this->localizer = $localizer;
}
/**
* Build the menu data array that can be passed to views/javascript
* @param array $personalTools Personal tools list generated by Skin::buildPersonalUrls
* @return string|null
*/
public function renderMenuData( array $personalTools ) {
$group = $this->builder->getGroup( $personalTools );
$entries = $group->getEntries();
$templateParser = new TemplateParser( __DIR__ . '/../../Skins' );
return empty( $entries )
? null
: $templateParser->processTemplate( 'ToggleList', [
'class' => 'minerva-user-menu',
'checkboxID' => 'minerva-user-menu-checkbox',
'toggleID' => 'minerva-user-menu-toggle', // See skin.mustache too.
'toggleClass' => MinervaUI::iconClass(
'userAvatarOutline', 'element'
),
'listID' => $group->getId(),
'listClass' => 'minerva-user-menu-list toggle-list__list--drop-down', // See ToggleList/*.less.
'text' => $this->localizer->msg( 'minerva-user-menu-button' )->escaped(),
'analyticsEventName' => 'ui.usermenu',
'items' => $entries
] );
}
}