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

Allow passing order information to BaseGroupedMapper::add method #8007

Closed HeldVomErdbeerfeld closed 1 year ago

HeldVomErdbeerfeld commented 1 year ago

Feature Request

It would be a great feature to pass order information when adding a field to a BaseGroupedMapper (e.g. FormMapper, ShowMapper etc) out of the box.

Usecase is when adding fields in a generic AdminExtension

So we currently use following workaround methods:

public function addAfter(string $after, $name, $type = null, array $fieldDescriptionOptions = [])
public function addBefore(string $before, $name, $type = null, array $fieldDescriptionOptions = [])

that simply add the field to the mapper and afterwards trigger a $formMapper->reorder($newCalculatedOrder);

Since the FormMapper and ShowMapper are final this workaround is realy ugly when trying to respect the form groups and tabs.

Can you imagine to allow adding this as feature of the SonataAdminBundle.

Maybe by passing two new fieldDescriptionOptions

'insert_at' => [
  'relative_to' => $fieldName, // any other field that has been added before
  'position'    => 'before'    // or 'after'
]

It may be thinkable to pass multiple elements to insert at to be more failsafe if $fiendName does not exist.

'insert_at' => [
  [
    'relative_to' => $fieldName,
    'position'    => 'after' 
  ],
  [
    'relative_to' => '_actions',
    'position'    => 'before' 
  ],
]

When implementing this, the new field should be added in the same tab and group where the addPositionReference is placed in. $currentGroup and $currentTab of BaseGroupedMapper shouldnt be changed when invoking this add method to beware of sideEffects

github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.