| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
namespace MediaWiki\Minerva\Menu\Entries; |
| 19 |
|
| 20 |
use MediaWiki\Title\Title; |
| 21 |
use MediaWiki\User\UserIdentity; |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
final class ProfileMenuEntry implements IProfileMenuEntry { |
| 27 |
private UserIdentity $user; |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
private ?string $profileTrackingCode = null; |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
private ?string $customProfileURL = null; |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
private ?string $customProfileLabel = null; |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
public function __construct( UserIdentity $user ) { |
| 51 |
$this->user = $user; |
| 52 |
} |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
public function getName(): string { |
| 58 |
return 'profile'; |
| 59 |
} |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
public function overrideProfileURL( |
| 65 |
$customURL, $customLabel = null, $trackingCode = null |
| 66 |
): self { |
| 67 |
$this->customProfileURL = $customURL; |
| 68 |
$this->customProfileLabel = $customLabel; |
| 69 |
$this->profileTrackingCode = $trackingCode; |
| 70 |
return $this; |
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
public function getCSSClasses(): array { |
| 77 |
return []; |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
public function getComponents(): array { |
| 84 |
$username = $this->user->getName(); |
| 85 |
return [ [ |
| 86 |
'data-icon' => [ |
| 87 |
'icon' => 'userAvatar', |
| 88 |
], |
| 89 |
'label' => $this->customProfileLabel ?? $username, |
| 90 |
'array-attributes' => [ |
| 91 |
[ |
| 92 |
'key' => 'href', |
| 93 |
'value' => $this->customProfileURL ?? Title::makeTitle( NS_USER, $username )->getLocalURL(), |
| 94 |
], |
| 95 |
[ |
| 96 |
'key' => 'data-event-name', |
| 97 |
'value' => 'menu.' . ( |
| 98 |
$this->profileTrackingCode ?? self::DEFAULT_PROFILE_TRACKING_CODE |
| 99 |
) |
| 100 |
], |
| 101 |
], |
| 102 |
'classes' => 'menu__item--user', |
| 103 |
] ]; |
| 104 |
} |
| 105 |
} |