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

Autowire problem since 1.2 because of $translator #945

Open

Description

@ITtoponline

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.

Activity

  1. DetaX commented on Sep 16, 2020

    @DetaX

    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', '', '', '']
    
  2. ahmedrabii commented on Apr 25, 2021

    @ahmedrabii

    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 join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions