move hook to render service

This commit is contained in:
dianafa 2015-09-28 17:46:40 +02:00
parent 864e644343
commit 4536458992
3 changed files with 7 additions and 4 deletions

View file

@ -78,11 +78,15 @@ class PortableInfoboxRenderServiceHelper {
*/
public function extendImageData( $data ) {
$thumbnail = $this->getThumbnail( $data[ 'name' ] );
$ref = null;
if ( !$thumbnail ) {
return false;
}
wfRunHooks( 'PortableInfoboxNodeImage::getData', [ $data, &$ref ] );
$data[ 'ref' ] = $ref;
$data[ 'height' ] = $thumbnail->getHeight();
$data[ 'width' ] = $thumbnail->getWidth();
$data[ 'thumbnail' ] = $thumbnail->getUrl();

View file

@ -27,15 +27,12 @@ class NodeImage extends Node {
$alt = $this->getValueWithDefault( $this->xmlNode->{self::ALT_TAG_NAME} );
$caption = $this->getValueWithDefault( $this->xmlNode->{self::CAPTION_TAG_NAME} );
wfRunHooks( 'PortableInfoboxNodeImage::getData', [ $title, &$ref, $caption ] );
$this->data = [
'url' => $this->resolveImageUrl( $file ),
'name' => ( $title ) ? $title->getText() : '',
'key' => ( $title ) ? $title->getDBKey() : '',
'alt' => $alt,
'caption' => $caption,
'ref' => $ref
'caption' => $caption
];
if ( $this->isVideo( $file ) ) {

View file

@ -4,6 +4,7 @@ use Wikia\PortableInfobox\Helpers\PortableInfoboxRenderServiceHelper;
class PortableInfoboxRenderService extends WikiaService {
const MOBILE_TEMPLATE_POSTFIX = '-mobile';
const MEDIA_CONTEXT_INFOBOX_HERO_IMAGE = 'infobox-hero-image';
private static $templates = [
'wrapper' => 'PortableInfoboxWrapper.mustache',
@ -128,6 +129,7 @@ class PortableInfoboxRenderService extends WikiaService {
if ( array_key_exists( 'image', $data ) ) {
$data[ 'image' ] = $helper->extendImageData( $data[ 'image' ] );
$data[ 'image' ][ 'context' ] = self::MEDIA_CONTEXT_INFOBOX_HERO_IMAGE;
$markup = $this->renderItem( 'hero-mobile', $data );
} else {
$markup = $this->renderItem( 'title', $data[ 'title' ] );