sonata-project / SonataAdminBundle

The missing Symfony Admin Generator
https://docs.sonata-project.org/projects/SonataAdminBundle
MIT License
2.11k stars 1.26k forks source link

[RFC] Unify parameter name holding sonata admin code from Request #7168

Closed franmomu closed 3 years ago

franmomu commented 3 years ago

Feature Request

Right now we have different parameter names for this (maybe there are more):

My idea was that we can use AdminFetcher for actions so we can remove some repeated code, but the problem is that AdminFetcher uses _sonata_admin: https://github.com/sonata-project/SonataAdminBundle/blob/38da565a75e687aaf791f3a3e16ed8dad220a629/src/Request/AdminFetcher.php#L35

That parameter could be changed to be configurable, but I think it's better to have consistency and always use the same name and extract it to a constant.

So if we unify these names, I would use the word code in it to make it explicit what it is, maybe _sonata_admin_code?

VincentLanglet commented 3 years ago

A lot have been done in my last PR.

Now there is

if (null !== $adminCode) { return $this->getAdminByAdminCode($adminCode); }


- `code` option in `AdminPreviewBlockService` and `AdminStatsBlockService` used this way

$admin = $this->pool->getAdminByAdminCode($blockContext->getSetting('code'));


- And I don't know where is used the following values in the `DefaultRouteGenerator`
    if ($admin->hasParentFieldDescription()) {
        /** @var array<string, mixed> $linkParameters */
        $linkParameters = $admin->getParentFieldDescription()->getOption('link_parameters', []);
        // merge link parameter if any provided by the parent field
        $parameters = array_merge($parameters, $linkParameters);

        $parameters['uniqid'] = $admin->getUniqid();
        $parameters['code'] = $admin->getCode();
        $parameters['pcode'] = $admin->getParentFieldDescription()->getAdmin()->getCode();
        $parameters['puniqid'] = $admin->getParentFieldDescription()->getAdmin()->getUniqid();
    }

    if ('update' === $name || '|update' === substr($name, -7)) {
        $parameters['uniqid'] = $admin->getUniqid();
        $parameters['code'] = $admin->getCode();
    }


Should we rename/remove some ?
VincentLanglet commented 3 years ago

I would say the last place we're using the request with another name than _sonata_admin is the SearchAction

I've started https://github.com/sonata-project/SonataAdminBundle/pull/7290 But I don't understand when/where are made the call to this action with an admin parameter.

VincentLanglet commented 3 years ago

I would say the last place we're using the request with another name than _sonata_admin is the SearchAction

I've started #7290 But I don't understand when/where are made the call to this action with an admin parameter.

Since we're deprecating the ability to pass an admin to the SearchAction https://github.com/sonata-project/SonataAdminBundle/pull/7290 I think we can close this issue.