Closed franmomu closed 3 years ago
A lot have been done in my last PR.
Now there is
admin_code
option in ModelAutocompleteType
used this way
{% if sonata_admin.admin is not null %}
'uniqid': '{{ sonata_admin.admin.uniqid }}',
'_sonata_admin': '{{ sonata_admin.admin.baseCodeRoute|e('js') }}',
{% elseif admin_code %}
'_sonata_admin': '{{ admin_code|e('js') }}',
{% endif %}
admin_code
option in AdminSearchBlockService
used this way
$admin = $this->pool->getAdminByAdminCode($blockContext->getSetting('admin_code'));
admin_code
option in AbstractFormContractor
used later this way
$adminCode = $fieldDescription->getOption('admin_code');
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 ?
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.
I would say the last place we're using the request with another name than
_sonata_admin
is the SearchActionI'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.
Feature Request
Right now we have different parameter names for this (maybe there are more):
_sonata_admin
: is used when creating routes: https://github.com/sonata-project/SonataAdminBundle/blob/38da565a75e687aaf791f3a3e16ed8dad220a629/src/Route/RouteCollection.php#L107-L109admin_code
: used in https://github.com/sonata-project/SonataAdminBundle/blob/38da565a75e687aaf791f3a3e16ed8dad220a629/src/Action/RetrieveAutocompleteItemsAction.php#L48code
: rest of the actions: https://github.com/sonata-project/SonataAdminBundle/blob/38da565a75e687aaf791f3a3e16ed8dad220a629/src/Action/AppendFormFieldElementAction.php#L54 https://github.com/sonata-project/SonataAdminBundle/blob/38da565a75e687aaf791f3a3e16ed8dad220a629/src/Action/RetrieveFormFieldElementAction.php#L53 https://github.com/sonata-project/SonataAdminBundle/blob/38da565a75e687aaf791f3a3e16ed8dad220a629/src/Action/SetObjectFieldValueAction.php#L116My idea was that we can use
AdminFetcher
for actions so we can remove some repeated code, but the problem is thatAdminFetcher
uses_sonata_admin
: https://github.com/sonata-project/SonataAdminBundle/blob/38da565a75e687aaf791f3a3e16ed8dad220a629/src/Request/AdminFetcher.php#L35That 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
?