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: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 
<?php
namespace Omeka\View\Helper;

use Omeka\Api\Representation\SitePageBlockRepresentation;
use Zend\Form\Element\Select;
use Zend\View\Helper\AbstractHelper;

/**
 * View helper for rendering a thumbnail type select element.
 */
class BlockThumbnailTypeSelect extends AbstractHelper
{
    /**
     * @var array
     */
    protected $thumbnailTypes;

    /**
     * Construct the helper.
     *
     * @param array $thumbnailTypes
     */
    public function __construct(array $thumbnailTypes)
    {
        $this->thumbnailTypes = $thumbnailTypes;
    }

    /**
     * Render a thumbnail type select element.
     *
     * @param SiteBlockAttachmentRepresentation|null $block
     * @return string
     */
    public function __invoke(SitePageBlockRepresentation $block = null)
    {
        $view = $this->getView();
        $type = null;
        if ($block) {
            $type = $block->dataValue('thumbnail_type');
        }

        $select = new Select('o:block[__blockIndex__][o:data][thumbnail_type]');
        $select->setValueOptions(array_combine($this->thumbnailTypes, $this->thumbnailTypes))->setValue($type);
        $html = '<div class="field"><div class="field-meta">';
        $html .= '<label class="thumbnail-option" for="o:block[__blockIndex__][o:data][thumbnail_type]">' . $view->translate('Thumbnail type') . '</label></div>';
        $html .= '<div class="inputs">' . $view->formSelect($select) . '</div></div>';
        return $html;
    }
}