2022-12-07 23:41:10 +00:00
|
|
|
<?php
|
|
|
|
namespace MediaWiki\Skins\Vector\Components;
|
|
|
|
|
2023-01-06 01:45:38 +00:00
|
|
|
use Countable;
|
|
|
|
|
2022-12-07 23:41:10 +00:00
|
|
|
/**
|
|
|
|
* VectorComponentMenu component
|
|
|
|
*/
|
2023-01-06 01:45:38 +00:00
|
|
|
class VectorComponentMenu implements VectorComponent, Countable {
|
2022-12-07 23:41:10 +00:00
|
|
|
/** @var array */
|
|
|
|
private $data;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $data
|
|
|
|
*/
|
2023-03-08 22:21:24 +00:00
|
|
|
public function __construct( array $data ) {
|
2022-12-07 23:41:10 +00:00
|
|
|
$this->data = $data;
|
2023-01-06 01:45:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Counts how many items the menu has.
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function count(): int {
|
|
|
|
$htmlItems = $this->data['html-items'] ?? '';
|
|
|
|
return substr_count( $htmlItems, '<li' );
|
2022-12-07 23:41:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function getTemplateData(): array {
|
|
|
|
return $this->data + [
|
|
|
|
'class' => '',
|
|
|
|
'label' => '',
|
|
|
|
'html-tooltip' => '',
|
|
|
|
'label-class' => '',
|
|
|
|
'heading-class' => '',
|
|
|
|
'html-before-portal' => '',
|
|
|
|
'html-items' => '',
|
|
|
|
'html-after-portal' => '',
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|