pimcore / output-data-config-toolkit

Output Data Config Toolkit community bundle adds some additional tools for formatting data outputs to Pimcore.
Other
21 stars 22 forks source link

[Bug]: Error with pimcore10.6 and OutputDataConfigToolkitBundle 4.1.11 #102

Closed js-aw closed 1 year ago

js-aw commented 1 year ago

Expected behavior

open the output config tab on an dataobject in pimcore backend then choose output channel

Actual behavior

opening the output config tab produces the following error with pimcore 10.6 and OutputDataConfigToolkitBundle 4.1.11:

Service "translator" not found: even though it exists in the app's container, the container inside "OutputDataConfigToolkitBundle\Controller\AdminController" is a smaller service locator that only knows about the "Pimcore\Security\User\TokenStorageUserResolver", "doctrine", "form.factory", "http_kernel", "message_bus", "messenger.default_bus", "parameter_bag", "pimcore.templating", "pimcore_admin.serializer", "request_stack", "router", "security.authorization_checker", "security.csrf.token_manager", "security.token_storage", "serializer", "session" and "twig" services. Try using dependency injection instead.

solution: change $translator = $this->get('translator'); to $translator = $this->translator; in output-data-config-toolkit-bundle/src/Controller/AdminController.php

Steps to reproduce

open the output config tab on an dataobject in pimcore backend. pimcore 10.6.x OutputDataConfigToolkitBundle: 4.1.11

dpfaffenbauer commented 1 year ago

Quick fix, add this to your services.yaml:


    OutputDataConfigToolkitBundle\Controller\ClassController:
        calls:
            - [setContainer, ['@service_container']]

    OutputDataConfigToolkitBundle\Controller\AdminController:
        calls:
            - [setContainer, ['@service_container' ]]
dpfaffenbauer commented 1 year ago

Nevermind, this creates other problems, better use this:

<?php

namespace AppBundle\DependencyInjection\CompilerPass;

use OutputDataConfigToolkitBundle\Controller\AdminController;
use OutputDataConfigToolkitBundle\Controller\ClassController;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;

class OutputDataConfigToolkitFixPass implements CompilerPassInterface
{
    public function process(ContainerBuilder $container)
    {
        $classDefinition = $container->getDefinition(ClassController::class);
        $classDefinition->addMethodCall('setContainer', [new Reference('service_container')]);

        $adminDefinition = $container->getDefinition(AdminController::class);
        $adminDefinition->addMethodCall('setContainer', [new Reference('service_container')]);
    }
}

and add it in your AppBundle 'build' method:

$container->addCompilerPass(new OutputDataConfigToolkitFixPass());
js-aw commented 1 year ago

great, i had helped myself in the meantime with a fork. but your suggestion is better, works thx.

dvesh3 commented 1 year ago

we also check if this is fixed on v5.0

kingjia90 commented 1 year ago

we also check if this is fixed on v5.0

On 5.0 it works because it's injected in the constructor

https://github.com/pimcore/output-data-config-toolkit/blob/253b06dd42bd544b954375050e2adb4a6c77db11/src/Controller/AdminController.php#L45C14-L47

In 4.1.11 could be just calling the setter injection in the parent do? https://github.com/pimcore/output-data-config-toolkit/blob/5fb1ed4aa0cf2999cdc46caa4bb49b5ca4d83fde/src/Controller/AdminController.php#L36 https://github.com/pimcore/pimcore/blob/8a435ad49a1b40e4a7ab0a7603b6557a4fe520a0/bundles/AdminBundle/Controller/AdminController.php#L57-L61

kingjia90 commented 1 year ago

103 seems working fine, but need to keep in mind to discard these change when merging 4.1 into 5.0

dvesh3 commented 1 year ago

Fixed by #103