Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extending SortableAdminController, problem with constructor #91

Open
romazabelin opened this issue Sep 29, 2021 · 2 comments
Open

Extending SortableAdminController, problem with constructor #91

romazabelin opened this issue Sep 29, 2021 · 2 comments

Comments

@romazabelin
Copy link

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
Copy link
Author

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

public function __construct(
        PropertyAccessorInterface $accessor,
        GedmoPositionHandler $positionHandler,

@dmitryuk
Copy link

Closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants