Initial commit
This commit is contained in:
36
src/Repository/MonsterRepository.php
Normal file
36
src/Repository/MonsterRepository.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?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,
|
||||
));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user