Skip to content

Commit 03d7c90

Browse files
author
david
committed
Added remove method in DoctrineAdminRepository and load admin repository in Entity from customAction in AdminController
1 parent 5520983 commit 03d7c90

4 files changed

Lines changed: 29 additions & 6 deletions

File tree

src/LIN3S/AdminBundle/Configuration/Model/Entity.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ final class Entity
2929
private $listOrderByDefault;
3030
private $printNames;
3131
private $repositoryServiceId;
32+
private $repository;
3233

3334
public function __construct(
3435
$name,
@@ -281,13 +282,24 @@ public function printNames()
281282
return $this->printNames;
282283
}
283284

284-
/**
285-
* Gets the repository service id.
286-
*
287-
* @return string
288-
*/
289285
public function repositoryServiceId()
290286
{
291287
return $this->repositoryServiceId;
292288
}
289+
290+
public function repository()
291+
{
292+
if (!$this->repository instanceof AdminRepository) {
293+
throw new \Exception(
294+
sprintf('The repository is not loaded yet')
295+
);
296+
}
297+
298+
return $this->repository;
299+
}
300+
301+
public function loadRepository(AdminRepository $repository)
302+
{
303+
$this->repository = $repository;
304+
}
293305
}

src/LIN3S/AdminBundle/Controller/AdminController.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,11 @@ public function customAction($entity, $action, $id = null, Request $request)
5757
{
5858
$entityConfig = $this->get('lin3s_admin.configuration.factory.entity')->createFor($entity);
5959
$entityObject = null;
60+
$repository = $this->get($entityConfig->repositoryServiceId());
61+
$entityConfig->loadRepository($repository);
62+
6063
if ($id) {
61-
$entityObject = $this->get($entityConfig->repositoryServiceId())->find($entityConfig, $id);
64+
$entityObject = $repository->find($entityConfig, $id);
6265
}
6366
if ($id && !$entityObject) {
6467
throw $this->createNotFoundException(

src/LIN3S/AdminBundle/Repository/AdminRepository.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ interface AdminRepository
2121
{
2222
public function find(Entity $config, $id);
2323

24+
public function remove($entity);
25+
2426
public function findByRequest(Request $request, Entity $config);
2527

2628
public function countAll(Request $request, Entity $config);

src/LIN3S/AdminBundle/Repository/DoctrineAdminRepository.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ public function find(Entity $config, $id)
3434
return $this->manager->find($config->className(), $id);
3535
}
3636

37+
public function remove($entity)
38+
{
39+
$this->manager->remove($entity);
40+
$this->manager->flush();
41+
}
42+
3743
public function findByRequest(Request $request, Entity $config)
3844
{
3945
$queryBuilder = $this->queryBuilder->generate($request, $config);

0 commit comments

Comments
 (0)