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 {
|
2023-11-08 01:01:59 +00:00
|
|
|
$items = $this->data['array-list-items'] ?? null;
|
|
|
|
if ( $items ) {
|
|
|
|
return count( $items );
|
|
|
|
}
|
2023-01-06 01:45:38 +00:00
|
|
|
$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' => '',
|
|
|
|
'html-before-portal' => '',
|
|
|
|
'html-items' => '',
|
|
|
|
'html-after-portal' => '',
|
2023-11-08 01:01:59 +00:00
|
|
|
'array-list-items' => null,
|
2022-12-07 23:41:10 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|