yokai-php / sonata-workflow

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

Sonata-admin dev-master and S5 missing sonata.admin.pool #28

Closed danaki closed 3 years ago

danaki commented 3 years ago

I'm using Symfony 5.2 and sonata-admin of the 4.x-dev branch (because 3.x requires symfony/console 4.x) and while using this bundle getting a strange error:

Unable to find the admin class related to the current controller (Yokai\SonataWorkflow\Controller\WorkflowController).

While digging into the issue I've found that there's actually another exception shadowed and probably wrongly rethrown in Sonata-admin's CRUD controller in configureAdmin() method:

...
        try {
            $this->admin = $this->get('sonata.admin.pool')->getAdminByAdminCode($adminCode);
        } catch (\InvalidArgumentException $e) {
dd($e);
            throw new \RuntimeException(sprintf(
                'Unable to find the admin class related to the current controller (%s).',
                static::class
            ));
        }
...
CRUDController.php on line 906:
Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException {#1066 ▼
  -id: "sonata.admin.pool"
  -sourceId: null
  -alternatives: []
  #message: "The "sonata.admin.pool" service or alias has been removed or inlined when the container was compiled. You should either make it public, or stop using the contai ▶"
  #code: 0
  #file: "/Users/up/work/project/vendor/symfony/dependency-injection/Container.php"
  #line: 266
  trace: {▶}
}

Seems that 'sonata.admin.pool' is not public service anymore but how that could be related to Sonata-Workflow bundle? Can you help me with this?

yann-eugone commented 3 years ago

Hey @danaki :)

You are right, this seems weird. Let's try to get some intel first :

danaki commented 3 years ago

Well, actually I'm using seemingly abandoned https://github.com/danaki/SonataAutoConfigureBundle that I've patched so that Symfony 5 doesnt complain and that could be the source of the issue, like so:

/**
 * @AdminOptions(
 *     label="Фидбеки",
 *     group="Для продуктов",
 *     entity=ProductFeedback::class,
 *     controller=Yokai\SonataWorkflow\Controller\WorkflowController::class
 * )
 */
class ProductFeedbackAdmin extends AbstractAdmin
...

however I'm using SortableBehaviorBundle which also requires controller to be rewritten in the similar manner.

Anyways, creating my own empty controller and using the trait fixed the error.

However there's another issue now that deserves it's own ticket, but... The error is gone, but transition menu is missing. And it seems there's something is going to be changed in upcoming Sonata Admin API, at least I grep'ed for "configureSideMenu" in vendor/sonata-project and haven't found anything.

yann-eugone commented 3 years ago

Not sure how the bundle works, but controller MUST be a service, it won't work otherwise.

Maybe sonata 4.x will allow different controllers in same admin, will save me lot of time :)

About your second issue, please open a new ticket, because method exists but was deprecated : https://github.com/sonata-project/SonataAdminBundle/blob/3.x/src/Admin/AdminExtensionInterface.php#L83