Section en-sonata

Symfony 4 / Sonata: Manage the Order with Drag'n Drop

Written by on 20/02/2020
Category:   PHP, Sonata
You need to install pixassociates/sortable-behavior-bundle and stof/doctrine-extensions-bundle composer require stof/doctrine-extensions-bundle composer require pixassociates/sortable-behavior-bundle Add the configuration in pix_sortable.yamlBy adding the entity and the field in position_field (here wconf, and the position field) pix_sortable_behavior: db_driver: orm # mongodb default value : orm position_field: default: position #default value : position entities: ...

Symfony 4 / Sonata: form types

Written by on 19/02/2020
Category:   PHP, Sonata
Tags:  
Here is a list of common form types used in admin interfaces.Date Time PickerAdd the template in the config/packages/twig.yaml file twig: form_themes: - '@SonataCore/Form/datepicker.html.twig' And in the controller: $formMapper->with('Date d\'activation', ['class' => 'col-md-4 abcdaire']) ->add('activation_debut', DatePickerType::class, ['required' => false, 'label'=>'Activation début','attr' => ['placeholder' => '']]) ...

Symfony 4 / Sonata add a filter linked to a OneToMany entity

Written by on 10/02/2020
Category:   PHP, Sonata
Tags:  
Filters are managed in the configureDatagridFilters method protected function configureDatagridFilters(DatagridMapper $datagridMapper) { $filers=$datagridMapper->getAdmin()->getFilterParameters(); } One can add a simple filter on a title or any parameter of our entity.The show_filter parameter allows to display it when the page loads. Combined with the value of $filters, one can specify to keep the element displayed after the filter submission.For example, one can set the filter to ...

Symfony 4 / Sonata: Using a primary key with a /

Written by on 10/02/2020
Category:   PHP, Sonata
Tags:  
As strange as it may seem, I had to use an entity with a primary key set on a varchar field, and some values contained a " / ".Until you are faced with the problem, it's impossible to imagine that it will cause an issue. And then, the drama unfolds. An exception has been thrown during the rendering of a template ("Parameter "id" for route "admin_app_wtype_edit" must match "[^/]++" ("MACHIN/CHOSE" given) to generate a corresponding URL."). In short, ...

Symfony 4 / Sonata: Create a OneToMany (1N) Administration

Written by on 15/01/2020
Category:   PHP, Sonata
Tags:  
We are going to create a 1N administration interface, with two entities. The first one, One, and the second, Many, and set up an admin panel for the One table, which can affect several elements of the Many table. To spice things up, we'll add some additional parameters, such as timestamp fields for sync dates with an SI, and primary fields that are not called ID and are not auto-incremented. In our case, we have a sync with an SI that requires a timestamp fi...