mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/Vector.git
synced 2024-12-03 03:37:24 +00:00
e153561255
Simplify the user links component Introduce MenuListItem and IconLink components. HTML changes: * Logout, login and account links are now wrapped in a ul and li tag instead of a DIV for consistent with other menus (this occurs due to use of MenuContents). Code reviewer can see tests for an understanding of how the template data and markup has changed. VISUAL CHANGE: * Increased margins in user links menu relating to change from DIV to UL / LI tags. Bug: T320927 Change-Id: Ia24be48105e1ff85da227883abb5dddb3d54388d
55 lines
1.1 KiB
PHP
55 lines
1.1 KiB
PHP
<?php
|
|
namespace MediaWiki\Skins\Vector\Components;
|
|
|
|
use Countable;
|
|
|
|
/**
|
|
* VectorComponentMenu component
|
|
*/
|
|
class VectorComponentMenu implements VectorComponent, Countable {
|
|
/** @var array */
|
|
private $data;
|
|
/** @var array */
|
|
private $items;
|
|
|
|
/**
|
|
* @param array $data
|
|
* @param VectorComponentMenuListItem[] $items
|
|
*/
|
|
public function __construct( array $data, array $items = [] ) {
|
|
$this->data = $data;
|
|
$this->items = $items;
|
|
}
|
|
|
|
/**
|
|
* Counts how many items the menu has.
|
|
*
|
|
* @return int
|
|
*/
|
|
public function count(): int {
|
|
$htmlItems = $this->data['html-items'] ?? '';
|
|
return substr_count( $htmlItems, '<li' );
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function getTemplateData(): array {
|
|
$dataItems = [];
|
|
foreach ( $this->items as $item ) {
|
|
$dataItems[] = $item->getTemplateData();
|
|
}
|
|
return $this->data + [
|
|
'class' => '',
|
|
'label' => '',
|
|
'html-tooltip' => '',
|
|
'label-class' => '',
|
|
'heading-class' => '',
|
|
'html-before-portal' => '',
|
|
'html-items' => '',
|
|
'html-after-portal' => '',
|
|
'data-items' => $dataItems,
|
|
];
|
|
}
|
|
}
|