Files
genshin-world/src/Repository/MonsterRepository.php
2025-07-15 23:39:10 +02:00

37 lines
1.5 KiB
PHP

<?php
namespace App\Repository;
use App\Entity\Monster;
use App\Entity\MonsterCategory;
use App\Form\MonsterType;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Routing\RouterInterface;
/**
* @method Monster|null find($id, $lockMode=null, $lockVersion=null)
* @method Monster|null findOneBy(array $criteria, array $orderBy=null)
* @method Monster[] findAll()
* @method Monster[] findBy(array $criteria, array $orderBy=null, $limit=null, $offset=null)
*/
class MonsterRepository extends ServiceEntityRepository {
public function __construct(ManagerRegistry $registry,
private RouterInterface $router,
private FormFactoryInterface $formFactory) {
parent::__construct($registry, Monster::class);
}
public function getForm(string $route, MonsterCategory $monsterCategory, Monster $monster): FormInterface {
$params=$monster->getId() !== null ? array('monsterCategoryId'=>$monsterCategory->getId(), 'id'=>$monster->getId()) : array('monsterCategoryId'=>$monsterCategory->getId());
return $this->formFactory->create(MonsterType::class, $monster, array(
'action'=>$this->router->generate($route, $params),
'method'=>'post',
'data_route'=>$route,
));
}
}