2022-10-27 19:36:08 +00:00
|
|
|
<?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;
|
2022-11-23 19:55:57 +00:00
|
|
|
/** @var string */
|
|
|
|
private $actionName;
|
2023-05-19 16:45:26 +00:00
|
|
|
/** @var string */
|
|
|
|
private $classes;
|
2022-10-27 19:36:08 +00:00
|
|
|
|
|
|
|
/**
|
2022-11-23 19:55:57 +00:00
|
|
|
* @param string $actionName identifier for the action. Used to add class
|
2022-10-27 19:36:08 +00:00
|
|
|
* @param Skin $skin
|
|
|
|
* @param array $htmlData data to make a link or raw html
|
|
|
|
* @param array $headingOptions optional heading for the html
|
2023-05-19 16:45:26 +00:00
|
|
|
* @param string $classes extra classes to add to this component
|
2022-10-27 19:36:08 +00:00
|
|
|
*/
|
2023-05-19 16:45:26 +00:00
|
|
|
public function __construct(
|
|
|
|
string $actionName, Skin $skin, array $htmlData,
|
|
|
|
array $headingOptions, string $classes = ''
|
|
|
|
) {
|
2022-10-27 19:36:08 +00:00
|
|
|
$this->skin = $skin;
|
|
|
|
$this->htmlData = $htmlData;
|
|
|
|
$this->headingOptions = $headingOptions;
|
2022-11-23 19:55:57 +00:00
|
|
|
$this->actionName = $actionName;
|
2023-05-19 16:45:26 +00:00
|
|
|
$this->classes = $classes;
|
2022-10-27 19:36:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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'];
|
|
|
|
}
|
|
|
|
|
2023-10-21 18:26:30 +00:00
|
|
|
if ( $this->classes !== '' ) {
|
2023-05-19 16:45:26 +00:00
|
|
|
$headingOptions['class'] = $this->classes;
|
|
|
|
}
|
|
|
|
|
2022-10-27 19:36:08 +00:00
|
|
|
return $headingOptions + [
|
2022-11-23 19:55:57 +00:00
|
|
|
'action' => $this->actionName,
|
2022-10-27 19:36:08 +00:00
|
|
|
'html-content' => $htmlContent,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function getTemplateData(): array {
|
|
|
|
return $this->makeMainMenuActionData( $this->htmlData, $this->headingOptions );
|
|
|
|
}
|
|
|
|
}
|