mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/Vector.git
synced 2024-11-28 01:20:07 +00:00
bfeb729f84
Bug: T319355 Change-Id: I10a8e796f6f6744fcc79ff6b1eb8f1d42389acba
47 lines
1.3 KiB
PHP
47 lines
1.3 KiB
PHP
<?php
|
|
namespace MediaWiki\Skins\Vector\Components;
|
|
|
|
use Language;
|
|
use MediaWiki\MediaWikiServices;
|
|
use MediaWiki\StubObject\StubUserLang;
|
|
|
|
/**
|
|
* VectorComponentMenuVariants component
|
|
*/
|
|
class VectorComponentMenuVariants extends VectorComponentMenu {
|
|
|
|
/**
|
|
* @param array $data
|
|
* @param Language|StubUserLang $pageLang
|
|
* @param string $ariaLabel
|
|
*/
|
|
public function __construct( array $data, $pageLang, string $ariaLabel ) {
|
|
parent::__construct( $this->updateVariantsMenuLabel( $data, $pageLang, $ariaLabel ) );
|
|
}
|
|
|
|
/**
|
|
* Change the portlets menu so the label is the selected variant
|
|
* @param array $portletData
|
|
* @param Language|StubUserLang $pageLang
|
|
* @param string $ariaLabel
|
|
* @return array
|
|
*/
|
|
private function updateVariantsMenuLabel( array $portletData, $pageLang, string $ariaLabel ): array {
|
|
$languageConverterFactory = MediaWikiServices::getInstance()->getLanguageConverterFactory();
|
|
$converter = $languageConverterFactory->getLanguageConverter( $pageLang );
|
|
$portletData['label'] = $pageLang->getVariantname(
|
|
$converter->getPreferredVariant()
|
|
);
|
|
// T289523 Add aria-label data to the language variant switcher.
|
|
$portletData['aria-label'] = $ariaLabel;
|
|
return $portletData;
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function getTemplateData(): array {
|
|
return parent::getTemplateData();
|
|
}
|
|
}
|