mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/Vector.git
synced 2024-12-12 07:55:21 +00:00
07a26a9448
Bug: T350195 Change-Id: I6cbf45587475f0477657a7ce9309b2cd42da33c1
50 lines
921 B
PHP
50 lines
921 B
PHP
<?php
|
|
namespace MediaWiki\Skins\Vector\Components;
|
|
|
|
use Countable;
|
|
|
|
/**
|
|
* VectorComponentMenu component
|
|
*/
|
|
class VectorComponentMenu implements VectorComponent, Countable {
|
|
/** @var array */
|
|
private $data;
|
|
|
|
/**
|
|
* @param array $data
|
|
*/
|
|
public function __construct( array $data ) {
|
|
$this->data = $data;
|
|
}
|
|
|
|
/**
|
|
* Counts how many items the menu has.
|
|
*
|
|
* @return int
|
|
*/
|
|
public function count(): int {
|
|
$items = $this->data['array-list-items'] ?? null;
|
|
if ( $items ) {
|
|
return count( $items );
|
|
}
|
|
$htmlItems = $this->data['html-items'] ?? '';
|
|
return substr_count( $htmlItems, '<li' );
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function getTemplateData(): array {
|
|
return $this->data + [
|
|
'class' => '',
|
|
'label' => '',
|
|
'html-tooltip' => '',
|
|
'label-class' => '',
|
|
'html-before-portal' => '',
|
|
'html-items' => '',
|
|
'html-after-portal' => '',
|
|
'array-list-items' => null,
|
|
];
|
|
}
|
|
}
|