Browse Source

Refacturing configureFields avec getPanels

develop
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

); );
} }


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 public function updateEntity(EntityManagerInterface $entityManager, $entityInstance): void
{ {
$entityManager->update($entityInstance); $entityManager->update($entityInstance);

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

use EasyCorp\Bundle\EasyAdminBundle\Field\FormField; use EasyCorp\Bundle\EasyAdminBundle\Field\FormField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField; use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use Lc\SovBundle\Controller\AbstractAdminController; use Lc\SovBundle\Controller\AbstractAdminController;
use Lc\SovBundle\Factory\Newsletter\NewsletterFactory;
use Lc\SovBundle\Field\BooleanField; use Lc\SovBundle\Field\BooleanField;
use Lc\SovBundle\Field\CKEditorField; use Lc\SovBundle\Field\CKEditorField;
use Lc\SovBundle\Field\StatusField; use Lc\SovBundle\Field\StatusField;
); );
} }


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

} }

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

namespace Lc\SovBundle\Controller\Reminder; namespace Lc\SovBundle\Controller\Reminder;


use Doctrine\ORM\EntityManagerInterface; 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\Factory\Reminder\ReminderFactoryInterface;
use Lc\SovBundle\Form\Reminder\ReminderAdminFormType; use Lc\SovBundle\Form\Reminder\ReminderAdminFormType;
use Lc\SovBundle\Repository\Reminder\ReminderRepositoryQueryInterface; use Lc\SovBundle\Repository\Reminder\ReminderRepositoryQueryInterface;
{ {


protected EntityManagerInterface $entityManager; protected EntityManagerInterface $entityManager;
protected ReminderFactoryInterface $reminderFactory;
protected ReminderRepositoryQueryInterface $reminderRepositoryQuery; protected ReminderRepositoryQueryInterface $reminderRepositoryQuery;
protected FormFactoryInterface $formFactory; protected FormFactoryInterface $formFactory;
protected UrlGeneratorInterface $urlGenerator; protected UrlGeneratorInterface $urlGenerator;


public function __construct( public function __construct(
EntityManagerInterface $entityManager, EntityManagerInterface $entityManager,
ReminderFactoryInterface $reminderFactory,
ReminderRepositoryQueryInterface $reminderRepositoryQuery, ReminderRepositoryQueryInterface $reminderRepositoryQuery,
FormFactoryInterface $formFactory, FormFactoryInterface $formFactory,
UrlGeneratorInterface $urlGenerator, UrlGeneratorInterface $urlGenerator,
ParameterBagInterface $parameterBag ParameterBagInterface $parameterBag
) { ) {
$this->entityManager = $entityManager; $this->entityManager = $entityManager;
$this->reminderFactory = $reminderFactory;
$this->reminderRepositoryQuery = $reminderRepositoryQuery; $this->reminderRepositoryQuery = $reminderRepositoryQuery;
$this->formFactory = $formFactory; $this->formFactory = $formFactory;
$this->urlGenerator = $urlGenerator; $this->urlGenerator = $urlGenerator;


public function createEntity(string $crudAction = null, string $crudControllerFqcn = null, int $entityId = null) 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

use EasyCorp\Bundle\EasyAdminBundle\Field\NumberField; use EasyCorp\Bundle\EasyAdminBundle\Field\NumberField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField; use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use Lc\SovBundle\Controller\AbstractAdminController; use Lc\SovBundle\Controller\AbstractAdminController;
use Lc\SovBundle\Factory\Site\NewsFactory;
use Lc\SovBundle\Field\CKEditorField; use Lc\SovBundle\Field\CKEditorField;
use Lc\SovBundle\Field\ImageManagerField;
use Lc\SovBundle\Field\StatusField; use Lc\SovBundle\Field\StatusField;


abstract class NewsAdminController extends AbstractAdminController abstract class NewsAdminController extends AbstractAdminController
); );
} }



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

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

use EasyCorp\Bundle\EasyAdminBundle\Field\NumberField; use EasyCorp\Bundle\EasyAdminBundle\Field\NumberField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField; use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use Lc\SovBundle\Controller\AbstractAdminController; use Lc\SovBundle\Controller\AbstractAdminController;
use Lc\SovBundle\Factory\Site\PageFactory;
use Lc\SovBundle\Field\CKEditorField; use Lc\SovBundle\Field\CKEditorField;
use Lc\SovBundle\Field\StatusField; use Lc\SovBundle\Field\StatusField;


); );
} }


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


} }

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

use EasyCorp\Bundle\EasyAdminBundle\Field\IntegerField; use EasyCorp\Bundle\EasyAdminBundle\Field\IntegerField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField; use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator; use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
use Lc\SovBundle\Factory\Ticket\TicketFactory;
use Lc\SovBundle\Factory\Ticket\TicketFactoryInterface; use Lc\SovBundle\Factory\Ticket\TicketFactoryInterface;
use Lc\SovBundle\Factory\Ticket\TicketMessageFactoryInterface; use Lc\SovBundle\Factory\Ticket\TicketMessageFactoryInterface;
use Lc\SovBundle\Form\Ticket\TicketFormType; use Lc\SovBundle\Form\Ticket\TicketFormType;
use Lc\SovBundle\Model\Ticket\TicketModel; use Lc\SovBundle\Model\Ticket\TicketModel;
use Lc\SovBundle\Translation\TranslatorAdmin; use Lc\SovBundle\Translation\TranslatorAdmin;
use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;


class TicketAdminController extends AbstractAdminController class TicketAdminController extends AbstractAdminController
{ {
return TicketInterface::class; return TicketInterface::class;
} }


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

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

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



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


abstract class GroupUserAdminController extends AbstractAdminController abstract class GroupUserAdminController extends AbstractAdminController
{ {
TextField::new('title'), TextField::new('title'),
TextField::new('devAlias'), TextField::new('devAlias'),
]; ];
}


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

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

use Lc\SovBundle\Definition\RolesDefinition; use Lc\SovBundle\Definition\RolesDefinition;
use Lc\SovBundle\Definition\RolesDefinitionInterface; use Lc\SovBundle\Definition\RolesDefinitionInterface;
use Lc\SovBundle\Doctrine\EntityManager; use Lc\SovBundle\Doctrine\EntityManager;
use Lc\SovBundle\Factory\User\UserFactory;
use Lc\SovBundle\Translation\TranslatorAdmin; use Lc\SovBundle\Translation\TranslatorAdmin;
use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Session\SessionInterface; use Symfony\Component\HttpFoundation\Session\SessionInterface;
abstract class UserAdminController extends AbstractAdminController abstract class UserAdminController extends AbstractAdminController
{ {
protected $rolesDefinition; protected $rolesDefinition;

public function __construct( public function __construct(
SessionInterface $session, SessionInterface $session,
RequestStack $request, RequestStack $request,
->setChoices($this->rolesDefinition->getRolesList()) ->setChoices($this->rolesDefinition->getRolesList())
]; ];
} }

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

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



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

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


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


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


return $ticket; return $ticket;

Loading…
Cancel
Save