<?php
namespace App\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\OptionsResolver;
/**
* Class TextareaCounterType
* @package App\Form\Type
*/
final class TextareaCounterType extends AbstractType
{
/**
* {@inheritDoc}
*/
public function buildView(FormView $view, FormInterface $form, array $options)
{
$view->vars['limit'] = $options['limit'] ?: 0;
$view->vars['limit_help'] = $options['limit_help'] ?? null;
}
/**
* {@inheritDoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setRequired('limit');
$resolver->setAllowedTypes('limit', 'int');
$resolver->setDefined('limit_help');
}
/**
* {@inheritDoc}
*/
public function getParent(): ?string
{
return TextareaType::class;
}
}