Here is the code by the way (it's in the topic i thought i forgot)
Here is the code by the way (it's in the topic i thought i forgot)
Here is the code by the way :
namespace Controller\Admin; use Doctrine\Common\Cache\CacheProvider; use Maximal\Quantity\Entity\MaxQuantity; use Maximal\Quantity\Repository\MaxQuantityRepository; use Maximal\Quantity\Type\MaxQuantityType; use PrestaShopBundle\Controller\Admin\FrameworkBundleAdminController; use PrestaShopBundle\Security\Annotation\AdminSecurity; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; class MaxQuantityController extends FrameworkBundleAdminController { /** @AdminSecurity("is_granted('read', request.get('_legacy_controller'))") * @return void */ private $cache; public function __construct(CacheProvider $cache) { $this->cache = $cache; parent::construct(); } public function indexAction(MaxQuantityRepository $repository): Response { $produits = $repository->findAll(); return $this->render('@Modules/maximalQuantity/views/templates/admin/index.html.twig', ['produits'=>$produits]); } private function getToolbarButtons() { return [ 'add' => [ 'desc' => $this->trans('Add new maximal quantity', 'Modules.maximalquantity.admin'), 'icon' => 'add_circle_outline', 'href' => $this->generateUrl('module_quantity_create'), ], ]; } /** * Creation d'une nouvelle quantité maximale * * @param Request $request * * @return Response */ public function createAction (Request $request) { $produit = new MaxQuantity(); $maxQuantityFormBuilder = $this->get('maximal.quantity.form.identifiable_object.builder.quantity_form_builder'); $maxQuantityForm = $maxQuantityFormBuilder->getForm([MaxQuantityType::class]); $maxQuantityForm->handleRequest($request); $maxQuantityFormHandler = $this->get('maximal.quantity.form.identifiable_object.data_handler.quantity_form_data_handler'); $result = $maxQuantityFormHandler->handle($maxQuantityForm); if (null !== $result->getIdentifiableObjectId()) { $this->addFlash( 'success', $this->trans('Successful creation.', 'Admin.Notifications.Success') ); return $this->redirectToRoute('module_config'); } return $this-> render('@Modules/maximalquantity/views/templates/admin/create.html.twig', [ 'QuantityForm' => $maxQuantityForm->createView(), ]); } /** * Edit d'une quantité maximale * * @param Request $request * @param int $productId * * @return Response */ public function editAction(Request $request, $productId) { $maxQuantityFormBuilder = $this->get('maximal.quantity.form.identifiable_object.builder.quantity_form_builder'); $maxQuantityForm = $maxQuantityFormBuilder->getFormFor((int)$productId); $maxQuantityForm->handleRequest($request); $maxQuantityFormHandler = $this->get('maximal.quantity.identifiable_object.handler.quantity_form_handler'); $result = $maxQuantityFormHandler->handleFor((int) $productId, $maxQuantityForm); if ($result->isSubmitted() && $result->isValid()) { $this->addFlash('success', $this->trans('Successful update.', 'Admin.Notifications.Success')); return $this->redirectToRoute('module_config'); } return $this->render('@Modules/maximalquantity/views/templates/admin/create.html.twig', [ 'QuantityForm' => $maxQuantityForm->createView(), ]); } }