Newer
Older
activity-manager / src / Form / Project / ProjectEditForm.php
<?php
namespace App\Form\Project;

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;
use App\Entity\ProjectEntity;

class ProjectEditForm extends AbstractFormManager
{

    /**
     * Update fields with entity data
     *
     * @param ProjectEntity $project
     * @return self
     */
    public function updateFields(ProjectEntity $project): self
    {
        $this->form->setData([
            'name' => $project->getName(),
            'active' => $project->getActive(),
        ]);

        return $this;
    }

    /**
     * Update entity from form data
     *
     * @param ProjectEntity $project
     * @return self
     */
    public function updateProject(ProjectEntity $project): self
    {
        $data = $this->form->getData();

        $project->setName($data['name']);
        $project->setActive($data['active']);

        return $this;
    }

    /**
     *
     * {@inheritdoc}
     */
    public function getTemplate(): string
    {
        return '_includes/html/form/project/edit.html.twig';
    }

    /**
     *
     * {@inheritdoc}
     */
    protected function addFields($formBuilder, $options): void
    {
        $formBuilder->add('name', TextType::class, [
            'required' => true
        ])
            ->add('active', CheckboxType::class, [
            'required' => false
        ])
            ->add('submit', SubmitType::class);
    }
}