Initial commit
This commit is contained in:
36
src/Repository/ItemRepository.php
Normal file
36
src/Repository/ItemRepository.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Item;
|
||||
use App\Entity\ItemCategory;
|
||||
use App\Form\ItemType;
|
||||
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 Item|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method Item|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method Item[] findAll()
|
||||
* @method Item[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class ItemRepository extends ServiceEntityRepository {
|
||||
public function __construct(ManagerRegistry $registry,
|
||||
private RouterInterface $router,
|
||||
private FormFactoryInterface $formFactory) {
|
||||
parent::__construct($registry, Item::class);
|
||||
}
|
||||
|
||||
public function getForm(string $route, ItemCategory $itemCategory, Item $item): FormInterface {
|
||||
$params=$item->getId() !== null ? array('itemCategoryId'=>$itemCategory->getId(), 'id'=>$item->getId()) : array('itemCategoryId'=>$itemCategory->getId());
|
||||
|
||||
return $this->formFactory->create(ItemType::class, $item, array(
|
||||
'action'=>$this->router->generate($route, $params),
|
||||
'method'=>'post',
|
||||
'data_route'=>$route,
|
||||
));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user