mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
sf4 depreciation: repairing crud custom routes loader
This commit is contained in:
parent
42c2ac48d2
commit
0b8a22ae46
@ -36,8 +36,9 @@ use Chill\MainBundle\Pagination\PaginatorInterface;
|
||||
use Chill\MainBundle\CRUD\Form\CRUDDeleteEntityForm;
|
||||
|
||||
/**
|
||||
*
|
||||
* Class CRUDController
|
||||
*
|
||||
* @package Chill\MainBundle\CRUD\Controller
|
||||
*/
|
||||
class CRUDController extends AbstractController
|
||||
{
|
||||
@ -49,17 +50,41 @@ class CRUDController extends AbstractController
|
||||
* @var array
|
||||
*/
|
||||
protected $crudConfig;
|
||||
|
||||
|
||||
/**
|
||||
* @param array $config
|
||||
*/
|
||||
public function setCrudConfig(array $config)
|
||||
{
|
||||
$this->crudConfig = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $parameter
|
||||
* @return Response
|
||||
*/
|
||||
public function CRUD($parameter)
|
||||
{
|
||||
return new Response($parameter);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param $id
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse|Response
|
||||
*/
|
||||
public function delete(Request $request, $id)
|
||||
{
|
||||
return $this->deleteAction('delete', $request, $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $action
|
||||
* @param Request $request
|
||||
* @param $id
|
||||
* @param null $formClass
|
||||
* @return null|\Symfony\Component\HttpFoundation\RedirectResponse|Response|void
|
||||
*/
|
||||
protected function deleteAction(string $action, Request $request, $id, $formClass = null)
|
||||
{
|
||||
$this->onPreDelete($action, $request, $id);
|
||||
@ -129,12 +154,34 @@ class CRUDController extends AbstractController
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $action
|
||||
* @param Request $request
|
||||
*/
|
||||
protected function onPreDelete(string $action, Request $request) {}
|
||||
|
||||
/**
|
||||
* @param string $action
|
||||
* @param $entity
|
||||
* @param FormInterface $form
|
||||
* @param Request $request
|
||||
*/
|
||||
protected function onPreRemove(string $action, $entity, FormInterface $form, Request $request) {}
|
||||
|
||||
/**
|
||||
* @param string $action
|
||||
* @param $entity
|
||||
* @param FormInterface $form
|
||||
* @param Request $request
|
||||
*/
|
||||
protected function onPostRemove(string $action, $entity, FormInterface $form, Request $request) {}
|
||||
|
||||
/**
|
||||
* @param string $action
|
||||
* @param $entity
|
||||
* @param FormInterface $form
|
||||
* @param Request $request
|
||||
*/
|
||||
protected function removeEntity(string $action, $entity, FormInterface $form, Request $request)
|
||||
{
|
||||
$this->getDoctrine()
|
||||
@ -238,7 +285,6 @@ class CRUDController extends AbstractController
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $action
|
||||
* @param Request $request
|
||||
*/
|
||||
@ -941,37 +987,84 @@ class CRUDController extends AbstractController
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $action
|
||||
* @param $entity
|
||||
* @param Request $request
|
||||
* @return bool
|
||||
*/
|
||||
protected function hasCustomTemplate($action, $entity, Request $request): bool
|
||||
{
|
||||
return !empty($this->getActionConfig($action)['template']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $action
|
||||
* @param $entity
|
||||
* @param FormInterface $form
|
||||
* @param Request $request
|
||||
*/
|
||||
protected function onPreFlush(string $action, $entity, FormInterface $form, Request $request)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $action
|
||||
* @param $entity
|
||||
* @param FormInterface $form
|
||||
* @param Request $request
|
||||
*/
|
||||
protected function onPostFlush(string $action, $entity, FormInterface $form, Request $request)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $action
|
||||
* @param $entity
|
||||
* @param FormInterface $form
|
||||
* @param Request $request
|
||||
*/
|
||||
protected function onPrePersist(string $action, $entity, FormInterface $form, Request $request)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $action
|
||||
* @param $entity
|
||||
* @param FormInterface $form
|
||||
* @param Request $request
|
||||
*/
|
||||
protected function onPostPersist(string $action, $entity, FormInterface $form, Request $request)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $action
|
||||
* @param Request $request
|
||||
* @param $entity
|
||||
* @return null|Response
|
||||
*/
|
||||
protected function onPostFetchEntity($action, Request $request, $entity): ?Response
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $action
|
||||
* @param Request $request
|
||||
* @param $entity
|
||||
* @return null|Response
|
||||
*/
|
||||
protected function onPostCheckACL($action, Request $request, $entity): ?Response
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param object $entity
|
||||
* @param FormInterface $form
|
||||
* @param Request $request
|
||||
*/
|
||||
protected function onFormValid(object $entity, FormInterface $form, Request $request)
|
||||
{
|
||||
}
|
||||
@ -1007,26 +1100,44 @@ class CRUDController extends AbstractController
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $action
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getActionConfig(string $action)
|
||||
{
|
||||
return $this->crudConfig['actions'][$action];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return PaginatorFactory
|
||||
*/
|
||||
protected function getPaginatorFactory(): PaginatorFactory
|
||||
{
|
||||
return $this->get(PaginatorFactory::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TranslatorInterface
|
||||
*/
|
||||
protected function getTranslator(): TranslatorInterface
|
||||
{
|
||||
return $this->container->get('translator');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return AuthorizationHelper
|
||||
*/
|
||||
protected function getAuthorizationHelper(): AuthorizationHelper
|
||||
{
|
||||
return $this->container->get(AuthorizationHelper::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Role $role
|
||||
* @param Scope|null $scope
|
||||
* @return \Chill\MainBundle\Entity\Center[]
|
||||
*/
|
||||
protected function getReachableCenters(Role $role, Scope $scope = null)
|
||||
{
|
||||
return $this->getAuthorizationHelper()
|
||||
@ -1034,16 +1145,25 @@ class CRUDController extends AbstractController
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return EventDispatcherInterface
|
||||
*/
|
||||
protected function getEventDispatcher(): EventDispatcherInterface
|
||||
{
|
||||
return $this->get(EventDispatcherInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Resolver
|
||||
*/
|
||||
protected function getCrudResolver(): Resolver
|
||||
{
|
||||
return $this->get(Resolver::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public static function getSubscribedServices()
|
||||
{
|
||||
return \array_merge(
|
||||
|
@ -20,25 +20,58 @@
|
||||
|
||||
namespace Chill\MainBundle\CRUD\Routing;
|
||||
|
||||
use Symfony\Component\Config\Loader\Loader;
|
||||
use Symfony\Component\Routing\Route;
|
||||
use Symfony\Component\Routing\RouteCollection;
|
||||
|
||||
|
||||
/**
|
||||
* Class CRUDRoutesLoader
|
||||
* Load the route for CRUD
|
||||
*
|
||||
* @package Chill\MainBundle\CRUD\Routing
|
||||
*/
|
||||
class CRUDRoutesLoader
|
||||
class CRUDRoutesLoader extends Loader
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $config = [];
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $isLoaded = false;
|
||||
|
||||
/**
|
||||
* CRUDRoutesLoader constructor.
|
||||
*
|
||||
* @param $config
|
||||
*/
|
||||
public function __construct($config)
|
||||
{
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
public function load()
|
||||
/**
|
||||
* @param mixed $resource
|
||||
* @param null $type
|
||||
* @return bool
|
||||
*/
|
||||
public function supports($resource, $type = null)
|
||||
{
|
||||
return 'CRUD' === $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return RouteCollection
|
||||
*/
|
||||
public function load($resource, $type = null)
|
||||
{
|
||||
|
||||
if (true === $this->isLoaded) {
|
||||
throw new \RuntimeException('Do not add the "CRUD" loader twice');
|
||||
}
|
||||
|
||||
$collection = new RouteCollection();
|
||||
|
||||
foreach ($this->config as $config) {
|
||||
@ -48,6 +81,10 @@ class CRUDRoutesLoader
|
||||
return $collection;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $config
|
||||
* @return RouteCollection
|
||||
*/
|
||||
protected function loadConfig($config): RouteCollection
|
||||
{
|
||||
$collection = new RouteCollection();
|
||||
|
@ -30,6 +30,9 @@ chill_password_recover:
|
||||
resource: "@ChillMainBundle/config/routes/password_recover.yaml"
|
||||
prefix: "public/{_locale}/password"
|
||||
|
||||
chill_crud:
|
||||
resource: "@ChillMainBundle"
|
||||
type: CRUD
|
||||
|
||||
root:
|
||||
path: /
|
||||
|
@ -1,8 +1,8 @@
|
||||
services:
|
||||
# Chill\MainBundle\CRUD\Routing\CRUDRoutesLoader:
|
||||
#
|
||||
# tags:
|
||||
# - routing.loader
|
||||
Chill\MainBundle\CRUD\Routing\CRUDRoutesLoader:
|
||||
arguments:
|
||||
$config: '%chill_main_crud_route_loader_config%'
|
||||
tags: [ routing.loader ]
|
||||
|
||||
Chill\MainBundle\CRUD\Resolver\Resolver:
|
||||
arguments:
|
||||
|
Loading…
x
Reference in New Issue
Block a user