1:  2:  3:  4:  5:  6:  7:  8:  9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 
<?php
namespace Omeka\View\Helper;

use Omeka\Api\Representation\AbstractRepresentation;
use Zend\View\Helper\AbstractHtmlElement;

/**
 * View helper for rendering a thumbnail image.
 */
class Thumbnail extends AbstractHtmlElement
{
    /**
     * Render a thumbnail image.
     *
     * @param AbstractRepresentation $representation
     * @param string $type
     * @param array $attribs
     */
    public function __invoke(AbstractRepresentation $representation, $type, array $attribs = [])
    {
        $primaryMedia = $representation->primaryMedia();
        if (!$primaryMedia) {
            return '';
        }

        $attribs['src'] = $primaryMedia->thumbnailUrl($type);
        if (!isset($attribs['alt'])) {
            $attribs['alt'] = '';
        }

        return sprintf('<img %s>', $this->htmlAttribs($attribs));
    }
}