mediawiki-extensions-Echo/includes/formatters/EchoModelFormatter.php
libraryupgrader ef3d2b886d build: Updating mediawiki/mediawiki-phan-config to 0.9.0
Change-Id: I03333636654eff80d4fe7fa543ac9e6c321af891
2019-12-29 11:59:32 +00:00

36 lines
1,018 B
PHP

<?php
/**
* A formatter for the notification flyout popup. Just the bare data needed to
* render everything client-side.
*/
class EchoModelFormatter extends EchoEventFormatter {
/**
* @param EchoEventPresentationModel $model
* @return array
* @suppress SecurityCheck-DoubleEscaped
*/
protected function formatModel( EchoEventPresentationModel $model ) {
$data = $model->jsonSerialize();
$data['iconUrl'] = EchoIcon::getUrl( $model->getIconType(), $this->language->getDir() );
if ( isset( $data['links']['primary']['url'] ) ) {
$data['links']['primary']['url'] = wfExpandUrl( $data['links']['primary']['url'] );
}
// @phan-suppress-next-line PhanTypePossiblyInvalidDimOffset
foreach ( $data['links']['secondary'] as &$link ) {
// @phan-suppress-next-line PhanTypeMismatchDimAssignment
$link['url'] = wfExpandUrl( $link['url'] );
}
unset( $link );
$bundledIds = $model->getBundledIds();
if ( $bundledIds ) {
$data[ 'bundledIds' ] = $bundledIds;
}
return $data;
}
}