mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/Vector.git
synced 2024-11-23 23:33:54 +00:00
Component: VariantsMenu
Bug: T319355 Change-Id: I10a8e796f6f6744fcc79ff6b1eb8f1d42389acba
This commit is contained in:
parent
e153561255
commit
bfeb729f84
46
includes/Components/VectorComponentMenuVariants.php
Normal file
46
includes/Components/VectorComponentMenuVariants.php
Normal file
|
@ -0,0 +1,46 @@
|
|||
<?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();
|
||||
}
|
||||
}
|
|
@ -205,23 +205,6 @@ abstract class SkinVector extends SkinMustache {
|
|||
return ExtensionRegistry::getInstance()->isLoaded( 'UniversalLanguageSelector' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the portlets menu so the label is the selected variant
|
||||
* @param array $portletData
|
||||
* @return array
|
||||
*/
|
||||
final protected function updateVariantsMenuLabel( array $portletData ): array {
|
||||
$languageConverterFactory = MediaWikiServices::getInstance()->getLanguageConverterFactory();
|
||||
$pageLang = $this->getTitle()->getPageLanguage();
|
||||
$converter = $languageConverterFactory->getLanguageConverter( $pageLang );
|
||||
$portletData['label'] = $pageLang->getVariantname(
|
||||
$converter->getPreferredVariant()
|
||||
);
|
||||
// T289523 Add aria-label data to the language variant switcher.
|
||||
$portletData['aria-label'] = $this->msg( 'vector-language-variant-switcher-label' );
|
||||
return $portletData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate data needed to generate the sticky header.
|
||||
* FIXME: Move to VectorComponentStickyHeader
|
||||
|
|
|
@ -9,6 +9,7 @@ use MediaWiki\Skins\Vector\Components\VectorComponentLanguageDropdown;
|
|||
use MediaWiki\Skins\Vector\Components\VectorComponentMainMenu;
|
||||
use MediaWiki\Skins\Vector\Components\VectorComponentMenu;
|
||||
use MediaWiki\Skins\Vector\Components\VectorComponentMenuListItem;
|
||||
use MediaWiki\Skins\Vector\Components\VectorComponentMenuVariants;
|
||||
use MediaWiki\Skins\Vector\Components\VectorComponentPageTools;
|
||||
use MediaWiki\Skins\Vector\Components\VectorComponentSearchBox;
|
||||
use MediaWiki\Skins\Vector\Components\VectorComponentStickyHeader;
|
||||
|
@ -170,10 +171,6 @@ class SkinVector22 extends SkinVector {
|
|||
$parentData = $this->mergeViewOverflowIntoActions( $parentData );
|
||||
$portlets = $parentData['data-portlets'];
|
||||
|
||||
$parentData['data-portlets']['data-variants'] = $this->updateVariantsMenuLabel(
|
||||
$parentData['data-portlets']['data-variants']
|
||||
);
|
||||
|
||||
$langData = $parentData['data-portlets']['data-languages'] ?? null;
|
||||
$config = $this->getConfig();
|
||||
|
||||
|
@ -192,6 +189,11 @@ class SkinVector22 extends SkinVector {
|
|||
$loginLinkData = $this->buildLoginData( $returnto, $this->useCombinedLoginLink() );
|
||||
$createAccountData = $this->buildCreateAccountData( $returnto );
|
||||
$components = [
|
||||
'data-vector-variants' => new VectorComponentMenuVariants(
|
||||
$parentData['data-portlets']['data-variants'],
|
||||
$this->getTitle()->getPageLanguage(),
|
||||
$this->msg( 'vector-language-variant-switcher-label' )
|
||||
),
|
||||
'data-vector-user-links' => new VectorComponentUserLinks(
|
||||
$this->getContext(),
|
||||
$user,
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace MediaWiki\Skins\Vector;
|
||||
|
||||
use MediaWiki\Skins\Vector\Components\VectorComponentMenuVariants;
|
||||
use MediaWiki\Skins\Vector\Components\VectorComponentSearchBox;
|
||||
|
||||
/**
|
||||
|
@ -118,7 +119,12 @@ class SkinVectorLegacy extends SkinVector {
|
|||
// Special casing for Variant to change label to selected.
|
||||
// Hopefully we can revisit and possibly remove this code when the language switcher is moved.
|
||||
if ( $key === 'data-variants' ) {
|
||||
$portletData = $this->updateVariantsMenuLabel( $portletData );
|
||||
$variantMenu = new VectorComponentMenuVariants(
|
||||
$portletData,
|
||||
$this->getTitle()->getPageLanguage(),
|
||||
$this->msg( 'vector-language-variant-switcher-label' )
|
||||
);
|
||||
$portletData = $variantMenu->getTemplateData();
|
||||
}
|
||||
|
||||
$portletData = $this->updatePortletClasses(
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<div id="left-navigation">
|
||||
<nav aria-label="{{msg-namespaces}}">
|
||||
{{#data-associated-pages}}{{>Tabs}}{{/data-associated-pages}}
|
||||
{{#data-variants}}{{>VariantsDropdown}}{{/data-variants}}
|
||||
{{#data-vector-variants}}{{>VariantsDropdown}}{{/data-vector-variants}}
|
||||
</nav>
|
||||
</div>
|
||||
<div id="right-navigation" class="vector-collapsible">
|
||||
|
|
Loading…
Reference in a new issue