2015-11-16 16:05:07 +00:00
|
|
|
<?php
|
|
|
|
|
2022-11-01 22:01:23 +00:00
|
|
|
namespace MediaWiki\Extension\Notifications\Formatters;
|
|
|
|
|
2015-11-16 16:05:07 +00:00
|
|
|
/**
|
|
|
|
* A formatter for the notification flyout popup. Just the bare data needed to
|
|
|
|
* render everything client-side.
|
|
|
|
*/
|
2016-01-12 22:30:51 +00:00
|
|
|
class EchoModelFormatter extends EchoEventFormatter {
|
2015-11-16 16:05:07 +00:00
|
|
|
/**
|
|
|
|
* @param EchoEventPresentationModel $model
|
|
|
|
* @return array
|
|
|
|
*/
|
2024-03-15 08:27:36 +00:00
|
|
|
protected function formatModel( EchoEventPresentationModel $model ): array {
|
2015-11-16 16:05:07 +00:00
|
|
|
$data = $model->jsonSerialize();
|
2016-07-20 14:53:36 +00:00
|
|
|
$data['iconUrl'] = EchoIcon::getUrl( $model->getIconType(), $this->language->getDir() );
|
2016-02-23 17:46:36 +00:00
|
|
|
|
|
|
|
if ( isset( $data['links']['primary']['url'] ) ) {
|
|
|
|
$data['links']['primary']['url'] = wfExpandUrl( $data['links']['primary']['url'] );
|
|
|
|
}
|
|
|
|
|
2019-12-21 05:45:14 +00:00
|
|
|
// @phan-suppress-next-line PhanTypePossiblyInvalidDimOffset
|
2016-02-23 17:46:36 +00:00
|
|
|
foreach ( $data['links']['secondary'] as &$link ) {
|
2019-03-11 13:25:18 +00:00
|
|
|
// @phan-suppress-next-line PhanTypeMismatchDimAssignment
|
2016-02-23 17:46:36 +00:00
|
|
|
$link['url'] = wfExpandUrl( $link['url'] );
|
|
|
|
}
|
2019-07-09 21:03:50 +00:00
|
|
|
unset( $link );
|
2016-02-23 17:46:36 +00:00
|
|
|
|
2016-06-02 14:00:48 +00:00
|
|
|
$bundledIds = $model->getBundledIds();
|
|
|
|
if ( $bundledIds ) {
|
|
|
|
$data[ 'bundledIds' ] = $bundledIds;
|
|
|
|
}
|
|
|
|
|
2015-11-16 16:05:07 +00:00
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
}
|