<?php namespace App\Form\Actors; use App\Entity\ActorEntity; use App\Form\AbstractFormManager; use Symfony\Component\Form\Extension\Core\Type\CheckboxType; use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\Extension\Core\Type\TextType; class ActorEditForm extends AbstractFormManager { /** * Update field values with entity data * * @param ActorEntity $actor * @return self */ public function updateFields(ActorEntity $actor): self { $this->form->setData([ 'firstName' => $actor->getFirstName(), 'lastName' => $actor->getLastName(), 'nickname' => $actor->getNickname(), 'active' => $actor->getActive(), 'followed' => $actor->getFollowed(), ]); return $this; } /** * Update actor with the content * * @param ActorEntity $actor * @return self */ public function updateActor(ActorEntity $actor): self { $data = $this->form->getData(); $actor->setFirstName($data['firstName']); $actor->setLastName($data['lastName']); $actor->setNickname($data['nickname'] ?? ""); $actor->setActive($data['active']); $actor->setFollowed($data['followed']); return $this; } /** * {@inheritdoc} */ public function getTemplate(): string { return '_includes/html/form/actors/edit.html.twig'; } /** * {@inheritdoc} */ protected function addFields($formBuilder, $options): void { $formBuilder->add('firstName', TextType::class, [ 'required' => true ]) ->add('lastName', TextType::class, [ 'required' => true ]) ->add('nickname', TextType::class, [ 'required' => false ]) ->add('active', CheckboxType::class, [ 'required' => false ]) ->add('followed', CheckboxType::class, [ 'required' => false ]) ->add('submit', SubmitType::class); } }