<?php

/**
 * Questo file è parte di Pongho.
 *
 * @author Daniele De Nobili
 * @package Application\Admin
 */

namespace Application\Admin\Form;

/**
 * Campo immagine.
 *
 * @deprecated
 */
class ImageField extends FileField
{
    /**
     * {@inheritdoc}
     */
    protected function parseOptions()
    {
        $allowed_extensions = ['jpg', 'jpeg', 'gif', 'png'];

        if (array_key_exists('allowed_extensions', $this->options) && is_array($this->options['allowed_extensions'])) {
            $this->options['allowed_extensions'] = array_merge($this->options['allowed_extensions'], $allowed_extensions);
        } else {
            $this->options['allowed_extensions'] = $allowed_extensions;
        }

        parent::parseOptions();
    }

    /**
     * {@inheritdoc}
     */
    protected function getPreviewLinkCode()
    {
        if ($file = $this->getFileModel()) {
            $container = $this->get('subject')->getContainer();

            return $container->get('template_html')->generateTagBlock(
                'a',
                $container->get('language')->get('preview'),
                [
                    'href'  => $this->getFileModel()->path(),
                    'class' => 'modal',
                ]
            );
        }

        return null;
    }
}
