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: 51: 52: 53: 54: 55: 56: 57: 
<?php
namespace Omeka\Form\Element;

use Omeka\Stdlib\HtmlPurifier;
use Zend\Form\Element\Textarea;
use Zend\InputFilter\InputProviderInterface;

/**
 * Textarea element for HTML.
 *
 * Purifies the markup after form submission.
 */
class HtmlTextarea extends Textarea implements InputProviderInterface
{
    /**
     * @var HtmlPurifier
     */
    protected $htmlPurifier;

    public function getInputSpecification()
    {
        return [
            'name' => $this->getName(),
            'required' => false,
            'filters' => [
                [
                    'name' => 'callback',
                    'options' => [
                        'callback' => [$this, 'purifyHtml'],
                    ],
                ],
            ],
        ];
    }

    /**
     * Purify the HTML.
     *
     * @param string $html
     * @return string
     */
    public function purifyHtml($html)
    {
        return $this->htmlPurifier->purify($html);
    }

    /**
     * Set the HTML purifier service.
     *
     * @param HtmlPurifier $htmlPurifier
     */
    public function setHtmlPurifier(HtmlPurifier $htmlPurifier)
    {
        $this->htmlPurifier = $htmlPurifier;
    }
}