DatatablesBundle icon indicating copy to clipboard operation
DatatablesBundle copied to clipboard

Autowire problem since 1.2 because of $translator

Open ITtoponline opened this issue 5 years ago • 2 comments

As $translator has no type-hint anymore in the AbstractDatatable class, I get an error when defining my Datatable like that

This is a datatable.yaml file imported in services.yaml

services:
  _defaults:
    autowire: true      # Automatically injects dependencies in your services.
    autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
    public: true

  App\Datatables\UserDatatable:
    parent: sg_datatables.datatable.abstract
    autowire: true
    autoconfigure: false
    public: true

Well it says that $translator has no type-hint and should be configured explicitally.

ITtoponline avatar Apr 24 '20 08:04 ITtoponline

Translator has been typed object in DatatableFactory for legacy purposes. You can pass the translator in your config as such :

Sg\DatatablesBundle\Datatable\DatatableFactory:
        arguments: ['', '', '@translator', '', '', '']

DetaX avatar Sep 16 '20 08:09 DetaX

You can add a constructor to your UserDatatable class , If you insist on creating the service that's okay but with the default configuration a service is created automatically (Symfony 4)

use Symfony\Contracts\Translation\TranslatorInterface;

public function __construct(
        AuthorizationCheckerInterface $authorizationChecker,
        TokenStorageInterface $securityToken,
        TranslatorInterface $translator,
        RouterInterface $router,
        EntityManagerInterface $em,
        Environment $twig
    )
    {
        parent::__construct($authorizationChecker, $securityToken, $translator, $router, $em, $twig);
    }

To check if your service exists

php bin/console debug:container App\Datatables\UserDatatable

ahmedrabii avatar Apr 25 '21 03:04 ahmedrabii