/** * {@inheritDoc} */ public function render(MediaInterface $media, VariantInterface $variant, $url = NULL, $options = array()) { $attributes = array('title' => $media->getName() . ' (' . $variant->getMetaValue('size') . ')'); if (isset($options['attributes'])) { $attributes = array_merge($attributes, $options['attributes']); } $htmlAttributes = ''; foreach ($attributes as $key => $value) { if ($value !== NULL) { $htmlAttributes .= $key . '="' . $value . '" '; } } return sprintf('<a href="%s" %s>%s</a>', $url, $htmlAttributes, $media->getName()); }
/** * {@inheritDoc} */ public function render(MediaInterface $media, VariantInterface $variant, $url = NULL, $options = array()) { $attributes = array('title' => $media->getName(), 'width' => $variant->getMetaValue('width'), 'height' => $variant->getMetaValue('height')); if (isset($options['attributes'])) { $attributes = array_merge($attributes, $options['attributes']); } $htmlAttributes = ''; foreach ($attributes as $key => $value) { if ($value !== NULL) { $htmlAttributes .= $key . ($value !== '' ? '="' . $value . '"' : '') . ' '; } } return sprintf('<img src="%s" %s/>', $url, $htmlAttributes); }
/** * {@inheritDoc} */ public function render(MediaInterface $media, VariantInterface $variant, $url = NULL, $options = array()) { $availableModes = array('video', 'image', 'embedUrl', 'url'); $defaultOptions = array('mode' => 'video', 'attributes' => array()); $options = array_merge($defaultOptions, $options); if (!in_array($options['mode'], $availableModes)) { throw new InvalidArgumentException(sprintf('Invalid mode "%s" to render a Youtube Video. Allowed values: "%s"', $options['mode'], json_encode($availableModes))); } $id = $media->getMetaValue('id'); $embedUrl = sprintf(self::EMBED_URL, $id); if ($options['mode'] == 'embedUrl') { return $embedUrl; } if ($options['mode'] == 'url') { return sprintf(self::CANONICAL_URL, $id); } switch ($options['mode']) { case 'video': $options['attributes'] = array_merge(array('width' => $variant->getMetaValue('width', 420), 'height' => $variant->getMetaValue('height', 315), 'frameborder' => 0, 'allowfullscreen' => '', 'webkitAllowFullScreen' => '', 'mozallowfullscreen' => ''), $options['attributes']); break; case 'image': $options['attributes'] = array_merge(array('title' => $media->getName(), 'width' => $variant->getMetaValue('width', 420), 'height' => $variant->getMetaValue('height', 315)), $options['attributes']); break; } $htmlAttributes = ''; foreach ($options['attributes'] as $key => $value) { if ($value !== NULL) { $htmlAttributes .= $key . ($value !== '' ? '="' . $value . '"' : '') . ' '; } } if ($options['mode'] == 'video') { $code = sprintf('<iframe src="%s" %s></iframe>', $embedUrl, $htmlAttributes); } else { $code = sprintf('<img src="%s" %s/>', $url, $htmlAttributes); } return $code; }