Manually change position of entities in a ManyToMany field in SonataAdmin

17 views Asked by At

I work on a project on which I wish to make a list of articles manually sortable, so the administrators can change the order of display of the article on the front end.

Currently I have this code for the Form fields:

protected function configureFormFields(FormMapper $form): void
    {
        $form
            ->add('title')
            ->add('description')
            ->add('articles', ModelType::class,[
                'multiple' => true,
                'btn_add' => false
            ], [
                'sortable' => 'position'
            ])
        ;
    }

The articles can be added but they are ordered by their IDs in the database and it seems that the field description option 'sortable' does nothing here (maybe a misuse on my part). The "articles" are a ManyToMany relation between a Content entity and the Program entity.

I try to use a ModelListType but it doesn't work.

I want to make the articles manually sortable and not automatically by their IDs, so the administrators can change the positions of them, and they can appears in that order on the front end.

0

There are 0 answers