yokai-php / sonata-workflow

Integrate Symfony workflow component in Sonata Admin
MIT License
22 stars 11 forks source link

workflow.registry not fetchable on sf4.3 with traits #11

Closed BigBadBassMan closed 4 years ago

BigBadBassMan commented 5 years ago

This seems to be a resurface of #1 . I'm running symfony 4.3, sonata-workflow 0.1.2 and latest sonata. Also, I updated my services.yaml to include the definition of the WorkflowController, double checked all dumped the config via debug:container.

I even went so far as to try and define a setter injection for my custom controller, however this seems to have had no effect. Sonata must be loading the admins and associated controllers by other means than DI.

Still, since I'm using a custom controller and your WorkflowTrait, I am at a loss, as to what i could do.

Any thoughts on this, or points I may be missing?

yann-eugone commented 5 years ago

Maybe your controller is not a service, and this is why you do not have the setter called ?

BigBadBassMan commented 4 years ago

Sorry for the late reply, I was busy working on another project.

Maybe your controller is not a service, and this is why you do not have the setter called ?

Anyhow, no, thats not the case.

bin/console debug:container controller.module clearly states my controller as being public and a service:

 ---------------- ----------------------------------------------------------
  Option           Value
 ---------------- ----------------------------------------------------------
  Service ID       mdb.admin.controller.module
  Class            TUD\ModulDBBundle\Controller\Admin\ModuleAdminController
  Tags             controller.service_arguments
  Calls            setDompdf, setWorkflowRegistry
  Public           yes
  Synthetic        no
  Lazy             no
  Shared           yes
  Abstract         no
  Autowired        yes
  Autoconfigured   yes
 ---------------- ----------------------------------------------------------

while at the same time claiming that workflow.registry is private. Somehow, my setters (or argument injection...) are not being called, it seems as if Sonata is not fetching my custom controllers from the container and instead is instantiating it directly.

I worked around that by forking your extension, defining a public alias workflow.registry.pub for workflow.registry and changing the WorkflowControllerTrait::getWorkflow to use the public alias.

Works for me, but is surely not in the intended way to use this.

Maybe the culprit is not your extension but my combination of sf4.3 and sonata packages?

sonata-project/admin-bundle              3.53.0             The missing Symfony Admin Generator
sonata-project/block-bundle              3.18.1             Symfony SonataBlockBundle
sonata-project/cache                     2.0.1              Cache library
sonata-project/core-bundle               3.17.0             Symfony SonataCoreBundle
sonata-project/datagrid-bundle           2.5.0              Symfony SonataDatagridBundle
sonata-project/doctrine-extensions       1.3.1              Doctrine2 behavioral extensions
sonata-project/doctrine-orm-admin-bundle 3.10.0             Symfony Sonata / Integrate Doctrine ORM into the Sonata...
sonata-project/easy-extends-bundle       2.5.0              Symfony SonataEasyExtendsBundle
sonata-project/exporter                  2.0.1              Lightweight Exporter library
sonata-project/formatter-bundle          4.1.3              Symfony SonataFormatterBundle
sonata-project/intl-bundle               dev-master 5f9555d Symfony SonataIntlBundle
sonata-project/translation-bundle        2.4.2              SonataTranslationBundle
sonata-project/user-bundle               4.5.0              Symfony SonataUserBundle
yann-eugone commented 4 years ago

I may have one more idea. How is configured your admin controller base name, is it with FQCN or service id ?

Since service auto registering, services classes are also service ids, but in your case the service id is mdb.admin.controller.module. If you want sonata (and routing) to be able to use it as service, you must provide the service id.

BigBadBassMan commented 4 years ago

If you meant to tell me, that the third argument to the admin service configuration should be the service id of my controller you totaly nailed it!

This works!

arguments:
  - ~
  - MyEntityFQCN
  - MyAdminControllerServiceID 

So, the fault lies in the sonata documentation, not your bundle.