mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/Vector.git
synced 2024-12-01 10:46:54 +00:00
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();
|
||
|
}
|
||
|
}
|