DerDu/SPHERE-Framework

View on GitHub
Common/Frontend/Form/Repository/Field/TextArea.php

Summary

Maintainability
A
35 mins
Test Coverage
<?php
namespace SPHERE\Common\Frontend\Form\Repository\Field;

use SPHERE\Common\Frontend\Form\IFieldInterface;
use SPHERE\Common\Frontend\Form\Repository\AbstractTextField;
use SPHERE\Common\Frontend\Icon\IIconInterface;

/**
 * Class TextArea
 *
 * @package SPHERE\Common\Frontend\Form\Repository\Field
 */
class TextArea extends AbstractTextField implements IFieldInterface
{

    /**
     * @param string $Name
     * @param null|string $Placeholder
     * @param null|string $Label
     * @param IIconInterface $Icon
     * @param int $Rows
     */
    public function __construct(
        $Name,
        $Placeholder = '',
        $Label = '',
        IIconInterface $Icon = null,
        $Rows = 5
    ) {

        $this->Name = $Name;
        $this->Template = $this->getTemplate(__DIR__.'/TextArea.twig');
        $this->Template->setVariable('ElementHash', md5(uniqid(microtime(),true)));
        $this->Template->setVariable('ElementName', $Name);
        $this->Template->setVariable('ElementLabel', $Label);
        $this->Template->setVariable('ElementPlaceholder', $Placeholder);
        $this->Template->setVariable('ElementRows', $Rows);
        if (null !== $Icon) {
            $this->Template->setVariable('ElementIcon', $Icon);
        }
        $this->setPostValue($this->Template, $Name, 'ElementValue');
    }

    /**
     * @param int $Value
     * @param bool $allowLineFeed Default: Disabled
     *
     * @return TextArea
     */
    public function setMaxLengthValue($Value, $allowLineFeed = false)
    {

        $this->Template->setVariable('MaxLength', (int)$Value);
        if( !$allowLineFeed ) {
            $this->Template->setVariable('DisableLineFeed', 'DisableLineFeed');
        }
        return $this;
    }
}