Merge "Allow msg key to be overridable"

This commit is contained in:
jenkins-bot 2022-02-17 18:16:08 +00:00 committed by Gerrit Code Review
commit c9bd66df37
2 changed files with 14 additions and 3 deletions

View file

@ -26,6 +26,7 @@ use MediaWiki\Minerva\Menu\Entries\SingleMenuEntry;
use MediaWiki\Special\SpecialPageFactory;
use MediaWiki\User\UserIdentity;
use MediaWiki\User\UserOptionsLookup;
use Message;
use MWException;
use SpecialPage;
use Title;
@ -90,7 +91,7 @@ final class Definitions {
/**
* Perform message localization
* @param string $key to localize
* @return string
* @return Message
*/
public function msg( string $key ) {
return $this->context->msg( $key );

View file

@ -85,7 +85,7 @@ final class BuilderUtil {
foreach ( $navigationTools as $item ) {
$id = $item['id'] ?? null;
if ( $id && isset( $entryDefinitions[ $id ] ) ) {
foreach ( [ 'icon', 'class', 'href' ] as $overridableKey ) {
foreach ( [ 'icon', 'class', 'href', 'msg' ] as $overridableKey ) {
$override = $item[ $overridableKey ] ?? null;
if ( $override ) {
$entryDefinitions[$id][$overridableKey] = $override;
@ -95,9 +95,19 @@ final class BuilderUtil {
}
// Build the menu
foreach ( $entryDefinitions as $definition ) {
$msgKey = $definition['msg'] ?? null;
$text = null;
if ( $msgKey ) {
$msg = $definitions->msg( $msgKey );
$text = $msg->exists() ? $msg->text() : null;
}
if ( !$text ) {
$text = $definition['text'];
}
$entry = SingleMenuEntry::create(
$definition['name'],
$definition['text'],
$text,
$definition['href'],
$definition['class'],
$definition['icon']