| 1 |
<?php |
| 2 |
namespace MediaWiki\Skins\Vector\Components; |
| 3 |
|
| 4 |
use Skin; |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
class VectorComponentMainMenuAction implements VectorComponent { |
| 10 |
|
| 11 |
private $skin; |
| 12 |
|
| 13 |
private $htmlData; |
| 14 |
|
| 15 |
private $headingOptions; |
| 16 |
|
| 17 |
private $actionName; |
| 18 |
|
| 19 |
private $classes; |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
public function __construct( |
| 29 |
string $actionName, Skin $skin, array $htmlData, |
| 30 |
array $headingOptions, string $classes = '' |
| 31 |
) { |
| 32 |
$this->skin = $skin; |
| 33 |
$this->htmlData = $htmlData; |
| 34 |
$this->headingOptions = $headingOptions; |
| 35 |
$this->actionName = $actionName; |
| 36 |
$this->classes = $classes; |
| 37 |
} |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
private function makeMainMenuActionData( array $htmlData = [], array $headingOptions = [] ): array { |
| 46 |
$skin = $this->skin; |
| 47 |
$htmlContent = ''; |
| 48 |
|
| 49 |
if ( array_key_exists( 'link', $htmlData ) ) { |
| 50 |
$htmlContent = $skin->makeLink( 'link', $htmlData['link'] ); |
| 51 |
} elseif ( array_key_exists( 'html-content', $htmlData ) ) { |
| 52 |
$htmlContent = $htmlData['html-content']; |
| 53 |
} |
| 54 |
|
| 55 |
if ( $this->classes !== '' ) { |
| 56 |
$headingOptions['class'] = $this->classes; |
| 57 |
} |
| 58 |
|
| 59 |
return $headingOptions + [ |
| 60 |
'action' => $this->actionName, |
| 61 |
'html-content' => $htmlContent, |
| 62 |
]; |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
public function getTemplateData(): array { |
| 69 |
return $this->makeMainMenuActionData( $this->htmlData, $this->headingOptions ); |
| 70 |
} |
| 71 |
} |