pix-digital / pixSortableBehaviorBundle

Offers a sortable feature for your Symfony2 admin listing
MIT License
46 stars 78 forks source link

Extending SortableAdminController, problem with constructor #91

Open romazabelin opened 3 years ago

romazabelin commented 3 years ago

Hi. I create custom controller for class PromoPageAdmin and set it in the settings in admin.yaml

App\Admin\Action\Content\PromoPageAdmin:
        arguments: [ ~, App\Cms\Entity\Content\PromoPage, App\Cms\Controller\Content\PromoPageController ]
        calls:
            - setTranslationDomain: [ 'promo_page' ]
        tags:
            - { name: sonata.admin, manager_type: orm, label: promo_page_list }

And in controller

class PromoPageController extends SortableAdminController
{
    protected UploadHandler $uploadHandler;

    protected SerializerInterface $serializer;

    protected LoggerInterface $logger;

    protected EntityManagerInterface $entityManager;

public function __construct(
        PropertyAccessorInterface $accessor,
        PositionHandlerInterface $positionHandler,
        UploadHandler $uploadHandler, SerializerInterface $serializer, LoggerInterface $logger, EntityManagerInterface $entityManager
    )
    {
        $this->uploadHandler = $uploadHandler;
        $this->serializer = $serializer;
        $this->logger = $logger;
        $this->entityManager = $entityManager;

        parent::__construct($accessor, $positionHandler);
    }
}

But I got this error Cannot autowire service "App\Cms\Controller\Content\PromoPageController": argument "$positionHandler" of method "__construct()" references interface "Runroom\SortableBehaviorBundle\Service\PositionHandlerInterface" but no such service exists. You should maybe alias this interface to one of these existing services: "Runroom\SortableBehaviorBundle\Service\ORMPositionHandler", "Runroom\SortableBehaviorBundle\Service\GedmoPositionHandler".

I tried add in service.yaml: Runroom\SortableBehaviorBundle\Service\PositionHandlerInterface:

but next error: Cannot instantiate interface Runroom\SortableBehaviorBundle\Service\PositionHandlerInterface

romazabelin commented 3 years ago

I have fixed it . We need to use use Runroom\SortableBehaviorBundle\Service\GedmoPositionHandler in constructor

public function __construct(
        PropertyAccessorInterface $accessor,
        GedmoPositionHandler $positionHandler,
dmitryuk commented 2 years ago

Closed