| 1 |
<?php |
| 2 |
namespace MediaWiki\Skins\Vector\Components; |
| 3 |
|
| 4 |
use MediaWiki\Html\Html; |
| 5 |
use MediaWiki\Linker\Linker; |
| 6 |
use MessageLocalizer; |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
class VectorComponentLink implements VectorComponent { |
| 12 |
|
| 13 |
private $localizer; |
| 14 |
|
| 15 |
private $icon; |
| 16 |
|
| 17 |
private $href; |
| 18 |
|
| 19 |
private $text; |
| 20 |
|
| 21 |
private $accessKeyHint; |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
public function __construct( string $href, string $text, $icon = null, $localizer = null, $accessKeyHint = null ) { |
| 32 |
$this->href = $href; |
| 33 |
$this->text = $text; |
| 34 |
$this->icon = $icon; |
| 35 |
$this->localizer = $localizer; |
| 36 |
$this->accessKeyHint = $accessKeyHint; |
| 37 |
} |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
public function getTemplateData(): array { |
| 43 |
$localizer = $this->localizer; |
| 44 |
$accessKeyHint = $this->accessKeyHint; |
| 45 |
$additionalAttributes = []; |
| 46 |
if ( $localizer ) { |
| 47 |
$msg = $localizer->msg( $accessKeyHint . '-label' ); |
| 48 |
if ( $msg->exists() ) { |
| 49 |
$additionalAttributes[ 'aria-label' ] = $msg->text(); |
| 50 |
} |
| 51 |
} |
| 52 |
return [ |
| 53 |
'icon' => $this->icon, |
| 54 |
'text' => $this->text, |
| 55 |
'href' => $this->href, |
| 56 |
'html-attributes' => $localizer && $accessKeyHint ? Html::expandAttributes( |
| 57 |
Linker::tooltipAndAccesskeyAttribs( |
| 58 |
$accessKeyHint, |
| 59 |
[], |
| 60 |
[], |
| 61 |
$localizer |
| 62 |
) + $additionalAttributes |
| 63 |
) : '', |
| 64 |
]; |
| 65 |
} |
| 66 |
} |