Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
33.33% |
6 / 18 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
| VectorComponentMainMenuAction | |
33.33% |
6 / 18 |
|
66.67% |
2 / 3 |
16.67 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
| makeMainMenuActionData | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
20 | |||
| getTemplateData | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | namespace MediaWiki\Skins\Vector\Components; |
| 3 | |
| 4 | use MediaWiki\Skin\Skin; |
| 5 | |
| 6 | /** |
| 7 | * VectorComponentMainMenuAction component |
| 8 | */ |
| 9 | class VectorComponentMainMenuAction implements VectorComponent { |
| 10 | /** @var Skin */ |
| 11 | private $skin; |
| 12 | /** @var array */ |
| 13 | private $htmlData; |
| 14 | /** @var array */ |
| 15 | private $headingOptions; |
| 16 | /** @var string */ |
| 17 | private $actionName; |
| 18 | /** @var string */ |
| 19 | private $classes; |
| 20 | |
| 21 | /** |
| 22 | * @param string $actionName identifier for the action. Used to add class |
| 23 | * @param Skin $skin |
| 24 | * @param array $htmlData data to make a link or raw html |
| 25 | * @param array $headingOptions optional heading for the html |
| 26 | * @param string $classes extra classes to add to this component |
| 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 | * Generate data needed to create MainMenuAction item. |
| 41 | * @param array $htmlData data to make a link or raw html |
| 42 | * @param array $headingOptions optional heading for the html |
| 43 | * @return array keyed data for the MainMenuAction template |
| 44 | */ |
| 45 | private function makeMainMenuActionData( array $htmlData = [], array $headingOptions = [] ): array { |
| 46 | $skin = $this->skin; |
| 47 | $htmlContent = ''; |
| 48 | // Populates the main menu as a standalone link or custom html. |
| 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 | * @inheritDoc |
| 67 | */ |
| 68 | public function getTemplateData(): array { |
| 69 | return $this->makeMainMenuActionData( $this->htmlData, $this->headingOptions ); |
| 70 | } |
| 71 | } |