mediawiki-skins-Vector/includes/Components/VectorComponentPinnableHeader.php
bwang 0f7411bdf2 Update TOC to use PinnableHeader
- Update 'collapsed' naming convention to 'pinned'
- Introduce VectorComponentPinnableHeader

Bug: T317897
Change-Id: I752eadc9bf54d58c799060a9eaefa0b125dd7952
2022-11-15 16:37:50 -06:00

60 lines
1.5 KiB
PHP

<?php
namespace MediaWiki\Skins\Vector\Components;
use MessageLocalizer;
/**
* VectorComponentPinnableHeader component
*/
class VectorComponentPinnableHeader implements VectorComponent {
/** @var MessageLocalizer */
private $localizer;
/** @var bool */
private $pinned;
/** @var string */
private $name;
/** @var bool */
private $moveElement;
/**
* @param MessageLocalizer $localizer
* @param bool $pinned
* @param string $name
* @param bool|null $moveElement
*/
public function __construct(
MessageLocalizer $localizer,
bool $pinned,
string $name,
?bool $moveElement = true
) {
$this->localizer = $localizer;
$this->pinned = $pinned;
$this->name = $name;
$this->moveElement = $moveElement;
}
/**
* @inheritDoc
*/
public function getTemplateData(): array {
$messageLocalizer = $this->localizer;
$data = [
'is-pinned' => $this->pinned,
'label' => $messageLocalizer->msg( $this->name . '-label' ),
'pin-label' => $messageLocalizer->msg( 'vector-pin-element-label' ),
'unpin-label' => $messageLocalizer->msg( 'vector-unpin-element-label' ),
'data-name' => $this->name
];
if ( $this->moveElement ) {
// Assumes consistent naming standard for pinnable elements and their containers
$data = array_merge( $data, [
'data-pinnable-element-id' => $this->name . '-content',
'data-unpinned-container-id' => $this->name . '-content-container',
'data-pinned-container-id' => $this->name . '-pinned-container',
] );
}
return $data;
}
}