1<?php
2/**
3 * Zend Framework (http://framework.zend.com/)
4 *
5 * @link      http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license   http://framework.zend.com/license/new-bsd New BSD License
8 */
9
10namespace Zend\Form\View\Helper;
11
12use Zend\Form\ElementInterface;
13use Zend\Form\Exception;
14
15class FormImage extends FormInput
16{
17    /**
18     * Attributes valid for the input tag type="image"
19     *
20     * @var array
21     */
22    protected $validTagAttributes = array(
23        'name'           => true,
24        'alt'            => true,
25        'autofocus'      => true,
26        'disabled'       => true,
27        'form'           => true,
28        'formaction'     => true,
29        'formenctype'    => true,
30        'formmethod'     => true,
31        'formnovalidate' => true,
32        'formtarget'     => true,
33        'height'         => true,
34        'src'            => true,
35        'type'           => true,
36        'width'          => true,
37    );
38
39    /**
40     * Render a form <input> element from the provided $element
41     *
42     * @param  ElementInterface $element
43     * @throws Exception\DomainException
44     * @return string
45     */
46    public function render(ElementInterface $element)
47    {
48        $src = $element->getAttribute('src');
49        if (empty($src)) {
50            throw new Exception\DomainException(sprintf(
51                '%s requires that the element has an assigned src; none discovered',
52                __METHOD__
53            ));
54        }
55
56        return parent::render($element);
57    }
58
59    /**
60     * Determine input type to use
61     *
62     * @param  ElementInterface $element
63     * @return string
64     */
65    protected function getType(ElementInterface $element)
66    {
67        return 'image';
68    }
69}
70