Skip to content
This repository has been archived by the owner on Feb 4, 2023. It is now read-only.

Autowire problem since 1.2 because of $translator #945

Open
ITtoponline opened this issue Apr 24, 2020 · 2 comments
Open

Autowire problem since 1.2 because of $translator #945

ITtoponline opened this issue Apr 24, 2020 · 2 comments

Comments

@ITtoponline
Copy link

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.

@DetaX
Copy link

DetaX commented Sep 16, 2020

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', '', '', '']

@ahmedrabii
Copy link

ahmedrabii commented Apr 25, 2021

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

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

No branches or pull requests

3 participants