Jump to content

Recommended Posts

Hello everyone !

As my pseudo say, i'm a junior developer and i have some issues with a module i'm creating.

When i install my module, and click on the configure button, i have an error : "the controller is missing or invalid".

 

I don't understand why because it's in the right folder, plus i declared it in the services.yaml.

Do you have any idea why ? 

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(),
        ]);
    }
}

 

Thanks for any help ! 

Edited by BabyDeveloper (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...