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;
|
2023-01-06 01:45:38 +00:00
|
|
|
/** @var array */
|
|
|
|
private $items;
|
2022-12-07 23:41:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $data
|
2023-01-06 01:45:38 +00:00
|
|
|
* @param VectorComponentMenuListItem[] $items
|
2022-12-07 23:41:10 +00:00
|
|
|
*/
|
2023-01-06 01:45:38 +00:00
|
|
|
public function __construct( array $data, array $items = [] ) {
|
2022-12-07 23:41:10 +00:00
|
|
|
$this->data = $data;
|
2023-01-06 01:45:38 +00:00
|
|
|
$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' );
|
2022-12-07 23:41:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function getTemplateData(): array {
|
2023-01-06 01:45:38 +00:00
|
|
|
$dataItems = [];
|
|
|
|
foreach ( $this->items as $item ) {
|
|
|
|
$dataItems[] = $item->getTemplateData();
|
|
|
|
}
|
2022-12-07 23:41:10 +00:00
|
|
|
return $this->data + [
|
|
|
|
'class' => '',
|
|
|
|
'label' => '',
|
|
|
|
'html-tooltip' => '',
|
|
|
|
'label-class' => '',
|
|
|
|
'heading-class' => '',
|
|
|
|
'html-before-portal' => '',
|
|
|
|
'html-items' => '',
|
|
|
|
'html-after-portal' => '',
|
2023-01-06 01:45:38 +00:00
|
|
|
'data-items' => $dataItems,
|
2022-12-07 23:41:10 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|