| 1 |
<?php |
| 2 |
namespace MediaWiki\Skins\Vector\Components; |
| 3 |
|
| 4 |
use Countable; |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
class VectorComponentMenu implements VectorComponent, Countable { |
| 10 |
|
| 11 |
private $data; |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
public function __construct( array $data ) { |
| 17 |
$this->data = $data; |
| 18 |
} |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
public function count(): int { |
| 26 |
$items = $this->data['array-list-items'] ?? null; |
| 27 |
if ( $items ) { |
| 28 |
return count( $items ); |
| 29 |
} |
| 30 |
$htmlItems = $this->data['html-items'] ?? ''; |
| 31 |
return substr_count( $htmlItems, '<li' ); |
| 32 |
} |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
public function getTemplateData(): array { |
| 38 |
return $this->data + [ |
| 39 |
'class' => '', |
| 40 |
'label' => '', |
| 41 |
'html-tooltip' => '', |
| 42 |
'label-class' => '', |
| 43 |
'html-before-portal' => '', |
| 44 |
'html-items' => '', |
| 45 |
'html-after-portal' => '', |
| 46 |
'array-list-items' => null, |
| 47 |
]; |
| 48 |
} |
| 49 |
} |