<?php
namespace App\Form\Type;
use App\Entity\Profile\CarPricing;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\DataMapperInterface;
use Symfony\Component\Form\Exception;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\GreaterThan;
class CarPricingType extends AbstractType implements DataMapperInterface
{
/**
* @inheritDoc
*/
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder->add('provided', CheckboxType::class, [
'required' => false,
]);
$builder->setDataMapper($this);
}
/**
* @inheritDoc
*/
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => CarPricing::class,
'empty_data' => null,
]);
}
/**
* @inheritDoc
*/
public function mapDataToForms($viewData, $forms)
{
if (null === $viewData) {
return null;
}
if (!$viewData instanceof CarPricing) {
throw new Exception\UnexpectedTypeException($viewData, CarPricing::class);
}
/** @var FormInterface[] $forms */
$forms = iterator_to_array($forms);
$forms['provided']->setData($viewData->isProvided());
}
/**
* @inheritDoc
*/
public function mapFormsToData($forms, &$viewData): void
{
/** @var FormInterface[] $forms */
$forms = iterator_to_array($forms);
$viewData = new CarPricing(
$forms['provided']->getData()
);
}
}