mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/Vector.git
synced 2024-12-03 03:37:24 +00:00
d1c0e6cd6f
The languages alert is misleading when there are no languages and the user has JS disabled. This change adds a class to the alert if there are 0 languages, and then adds "display: none" to the alert if the client-nojs class is present. This is the same approach being used for the language switcher button. Bug: T326185 Change-Id: Iee292d661ed1f47700f588053712f5f547022b17
72 lines
2 KiB
PHP
72 lines
2 KiB
PHP
<?php
|
|
namespace MediaWiki\Skins\Vector\Components;
|
|
|
|
use Skin;
|
|
|
|
/**
|
|
* VectorComponentMainMenuAction component
|
|
*/
|
|
class VectorComponentMainMenuAction implements VectorComponent {
|
|
/** @var Skin */
|
|
private $skin;
|
|
/** @var array */
|
|
private $htmlData;
|
|
/** @var array */
|
|
private $headingOptions;
|
|
/** @var string */
|
|
private $actionName;
|
|
/** @var string */
|
|
private $classes;
|
|
|
|
/**
|
|
* @param string $actionName identifier for the action. Used to add class
|
|
* @param Skin $skin
|
|
* @param array $htmlData data to make a link or raw html
|
|
* @param array $headingOptions optional heading for the html
|
|
* @param string $classes extra classes to add to this component
|
|
*/
|
|
public function __construct(
|
|
string $actionName, Skin $skin, array $htmlData,
|
|
array $headingOptions, string $classes = ''
|
|
) {
|
|
$this->skin = $skin;
|
|
$this->htmlData = $htmlData;
|
|
$this->headingOptions = $headingOptions;
|
|
$this->actionName = $actionName;
|
|
$this->classes = $classes;
|
|
}
|
|
|
|
/**
|
|
* Generate data needed to create MainMenuAction item.
|
|
* @param array $htmlData data to make a link or raw html
|
|
* @param array $headingOptions optional heading for the html
|
|
* @return array keyed data for the MainMenuAction template
|
|
*/
|
|
private function makeMainMenuActionData( array $htmlData = [], array $headingOptions = [] ): array {
|
|
$skin = $this->skin;
|
|
$htmlContent = '';
|
|
// Populates the main menu as a standalone link or custom html.
|
|
if ( array_key_exists( 'link', $htmlData ) ) {
|
|
$htmlContent = $skin->makeLink( 'link', $htmlData['link'] );
|
|
} elseif ( array_key_exists( 'html-content', $htmlData ) ) {
|
|
$htmlContent = $htmlData['html-content'];
|
|
}
|
|
|
|
if ( !empty( $this->classes ) ) {
|
|
$headingOptions['class'] = $this->classes;
|
|
}
|
|
|
|
return $headingOptions + [
|
|
'action' => $this->actionName,
|
|
'html-content' => $htmlContent,
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function getTemplateData(): array {
|
|
return $this->makeMainMenuActionData( $this->htmlData, $this->headingOptions );
|
|
}
|
|
}
|