Browse Source

Refacturing configureFields avec getPanels

feature/symfony6.1
Fab 3 years ago
parent
commit
d2cf289011
9 changed files with 47 additions and 26 deletions
  1. +0
    -12
      Controller/AbstractAdminController.php
  2. +7
    -0
      Controller/Newsletter/NewsletterAdminController.php
  3. +5
    -4
      Controller/Reminder/ReminderAdminController.php
  4. +6
    -2
      Controller/Site/NewsAdminController.php
  5. +6
    -0
      Controller/Site/PageAdminController.php
  6. +7
    -1
      Controller/Ticket/TicketAdminController.php
  7. +6
    -0
      Controller/User/GroupUserAdminController.php
  8. +8
    -0
      Controller/User/UserAdminController.php
  9. +2
    -7
      Factory/Ticket/TicketFactory.php

+ 0
- 12
Controller/AbstractAdminController.php View File

@@ -379,18 +379,6 @@ abstract class AbstractAdminController extends EaAbstractCrudController
);
}

public function createEntity(string $entityFqcn)
{
if (method_exists($this, 'getEntityFactory')) {
$factoryClass = $this->getEntityFactory();
$factory = new $factoryClass;

return $factory->create();
} else {
return parent::createEntity($entityFqcn);
}
}

public function updateEntity(EntityManagerInterface $entityManager, $entityInstance): void
{
$entityManager->update($entityInstance);

+ 7
- 0
Controller/Newsletter/NewsletterAdminController.php View File

@@ -5,6 +5,7 @@ namespace Lc\SovBundle\Controller\Newsletter;
use EasyCorp\Bundle\EasyAdminBundle\Field\FormField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use Lc\SovBundle\Controller\AbstractAdminController;
use Lc\SovBundle\Factory\Newsletter\NewsletterFactory;
use Lc\SovBundle\Field\BooleanField;
use Lc\SovBundle\Field\CKEditorField;
use Lc\SovBundle\Field\StatusField;
@@ -30,4 +31,10 @@ abstract class NewsletterAdminController extends AbstractAdminController
);
}

public function createEntity(string $entityFqcn)
{
$factory = new NewsletterFactory();
return $factory->create();
}

}

+ 5
- 4
Controller/Reminder/ReminderAdminController.php View File

@@ -3,6 +3,9 @@
namespace Lc\SovBundle\Controller\Reminder;

use Doctrine\ORM\EntityManagerInterface;
use Lc\CaracoleBundle\Resolver\MerchantResolver;
use Lc\CaracoleBundle\Resolver\SectionResolver;
use Lc\SovBundle\Factory\Reminder\ReminderFactory;
use Lc\SovBundle\Factory\Reminder\ReminderFactoryInterface;
use Lc\SovBundle\Form\Reminder\ReminderAdminFormType;
use Lc\SovBundle\Repository\Reminder\ReminderRepositoryQueryInterface;
@@ -19,7 +22,6 @@ class ReminderAdminController extends AbstractController
{

protected EntityManagerInterface $entityManager;
protected ReminderFactoryInterface $reminderFactory;
protected ReminderRepositoryQueryInterface $reminderRepositoryQuery;
protected FormFactoryInterface $formFactory;
protected UrlGeneratorInterface $urlGenerator;
@@ -29,14 +31,12 @@ class ReminderAdminController extends AbstractController

public function __construct(
EntityManagerInterface $entityManager,
ReminderFactoryInterface $reminderFactory,
ReminderRepositoryQueryInterface $reminderRepositoryQuery,
FormFactoryInterface $formFactory,
UrlGeneratorInterface $urlGenerator,
ParameterBagInterface $parameterBag
) {
$this->entityManager = $entityManager;
$this->reminderFactory = $reminderFactory;
$this->reminderRepositoryQuery = $reminderRepositoryQuery;
$this->formFactory = $formFactory;
$this->urlGenerator = $urlGenerator;
@@ -149,6 +149,7 @@ class ReminderAdminController extends AbstractController

public function createEntity(string $crudAction = null, string $crudControllerFqcn = null, int $entityId = null)
{
return $this->reminderFactory->create($crudAction, $crudControllerFqcn, $entityId);
$factory = new ReminderFactory();
return $factory->create($crudAction, $crudControllerFqcn, $entityId);
}
}

+ 6
- 2
Controller/Site/NewsAdminController.php View File

@@ -7,8 +7,8 @@ use EasyCorp\Bundle\EasyAdminBundle\Field\FormField;
use EasyCorp\Bundle\EasyAdminBundle\Field\NumberField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use Lc\SovBundle\Controller\AbstractAdminController;
use Lc\SovBundle\Factory\Site\NewsFactory;
use Lc\SovBundle\Field\CKEditorField;
use Lc\SovBundle\Field\ImageManagerField;
use Lc\SovBundle\Field\StatusField;

abstract class NewsAdminController extends AbstractAdminController
@@ -34,5 +34,9 @@ abstract class NewsAdminController extends AbstractAdminController
);
}


public function createEntity(string $entityFqcn)
{
$factory = new NewsFactory();
return $factory->create();
}
}

+ 6
- 0
Controller/Site/PageAdminController.php View File

@@ -6,6 +6,7 @@ use EasyCorp\Bundle\EasyAdminBundle\Field\FormField;
use EasyCorp\Bundle\EasyAdminBundle\Field\NumberField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use Lc\SovBundle\Controller\AbstractAdminController;
use Lc\SovBundle\Factory\Site\PageFactory;
use Lc\SovBundle\Field\CKEditorField;
use Lc\SovBundle\Field\StatusField;

@@ -30,5 +31,10 @@ abstract class PageAdminController extends AbstractAdminController
);
}

public function createEntity(string $entityFqcn)
{
$factory = new PageFactory();
return $factory->create();
}

}

+ 7
- 1
Controller/Ticket/TicketAdminController.php View File

@@ -13,6 +13,7 @@ use EasyCorp\Bundle\EasyAdminBundle\Field\DateField;
use EasyCorp\Bundle\EasyAdminBundle\Field\IntegerField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
use Lc\SovBundle\Factory\Ticket\TicketFactory;
use Lc\SovBundle\Factory\Ticket\TicketFactoryInterface;
use Lc\SovBundle\Factory\Ticket\TicketMessageFactoryInterface;
use Lc\SovBundle\Form\Ticket\TicketFormType;
@@ -23,7 +24,6 @@ use Lc\SovBundle\Controller\AbstractAdminController;
use Lc\SovBundle\Model\Ticket\TicketModel;
use Lc\SovBundle\Translation\TranslatorAdmin;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;

class TicketAdminController extends AbstractAdminController
{
@@ -50,6 +50,12 @@ class TicketAdminController extends AbstractAdminController
return TicketInterface::class;
}

public function createEntity(string $entityFqcn)
{
$factory = new TicketFactory();
return $factory->create();
}

public function configureAssets(Assets $assets): Assets
{
$assets = parent::configureAssets($assets);

+ 6
- 0
Controller/User/GroupUserAdminController.php View File

@@ -4,6 +4,7 @@ namespace Lc\SovBundle\Controller\User;

use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use Lc\SovBundle\Controller\AbstractAdminController;
use Lc\SovBundle\Factory\User\GroupUserFactory;

abstract class GroupUserAdminController extends AbstractAdminController
{
@@ -14,6 +15,11 @@ abstract class GroupUserAdminController extends AbstractAdminController
TextField::new('title'),
TextField::new('devAlias'),
];
}

public function createEntity(string $entityFqcn)
{
$factory = new GroupUserFactory();
return $factory->create();
}
}

+ 8
- 0
Controller/User/UserAdminController.php View File

@@ -9,6 +9,7 @@ use Lc\SovBundle\Controller\AbstractAdminController;
use Lc\SovBundle\Definition\RolesDefinition;
use Lc\SovBundle\Definition\RolesDefinitionInterface;
use Lc\SovBundle\Doctrine\EntityManager;
use Lc\SovBundle\Factory\User\UserFactory;
use Lc\SovBundle\Translation\TranslatorAdmin;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
@@ -16,6 +17,7 @@ use Symfony\Component\HttpFoundation\Session\SessionInterface;
abstract class UserAdminController extends AbstractAdminController
{
protected $rolesDefinition;

public function __construct(
SessionInterface $session,
RequestStack $request,
@@ -39,4 +41,10 @@ abstract class UserAdminController extends AbstractAdminController
->setChoices($this->rolesDefinition->getRolesList())
];
}

public function createEntity(string $entityFqcn)
{
$factory = new UserFactory();
return $factory->create();
}
}

+ 2
- 7
Factory/Ticket/TicketFactory.php View File

@@ -8,18 +8,13 @@ use Lc\SovBundle\Model\Ticket\TicketInterface;

class TicketFactory extends AbstractFactory implements TicketFactoryInterface
{
protected TicketMessageFactoryInterface $ticketMessageFactory;

public function __construct(TicketMessageFactoryInterface $ticketMessageFactory)
{
$this->ticketMessageFactory = $ticketMessageFactory;
}

public function create(): TicketInterface
{
$ticket = new Ticket();

$ticketMessage = $this->ticketMessageFactory->create() ;
$ticketMessageFactory = new TicketMessageFactory();
$ticketMessage = $ticketMessageFactory->create() ;
$ticket->addTicketMessage($ticketMessage) ;

return $ticket;

Loading…
Cancel
Save