mirror of
https://github.com/StarCitizenTools/mediawiki-skins-Citizen.git
synced 2024-11-28 08:10:45 +00:00
53 lines
954 B
PHP
53 lines
954 B
PHP
|
<?php
|
||
|
|
||
|
declare( strict_types=1 );
|
||
|
|
||
|
namespace MediaWiki\Skins\Citizen\Components;
|
||
|
|
||
|
use Countable;
|
||
|
|
||
|
/**
|
||
|
* CitizenComponentMenu component
|
||
|
*/
|
||
|
class CitizenComponentMenu implements CitizenComponent, 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,
|
||
|
];
|
||
|
}
|
||
|
}
|