runroom-packages / sortable-behavior-bundle
Provides a way to sort your admin listing
Installs: 632 883
Dependents: 1
Suggesters: 0
Security: 0
Stars: 9
Watchers: 8
Forks: 7
Type:symfony-bundle
Requires
- php: ^8.1
- doctrine/dbal: ^3.6 || ^4.0
- doctrine/doctrine-bundle: ^2.10
- doctrine/orm: ^2.19 || ^3.2
- doctrine/persistence: ^3.1
- symfony/config: ^6.4 || ^7.1
- symfony/dependency-injection: ^6.4 || ^7.1
- symfony/http-foundation: ^6.4 || ^7.1
- symfony/http-kernel: ^6.4 || ^7.1
- symfony/property-access: ^6.4 || ^7.1
- symfony/translation: ^6.4 || ^7.1
- twig/twig: ^3.14
Requires (Dev)
- dama/doctrine-test-bundle: ^8.0
- gedmo/doctrine-extensions: ^3.11
- knplabs/knp-menu-bundle: ^3.1
- matthiasnoback/symfony-config-test: ^5.1
- matthiasnoback/symfony-dependency-injection-test: ^5.1
- phpunit/phpunit: ^9.6
- psr/container: ^1.1 || ^2.0
- runroom-packages/testing: ^0.20
- sonata-project/admin-bundle: ^4.25
- sonata-project/doctrine-orm-admin-bundle: ^4.13
- symfony/browser-kit: ^6.4 || ^7.1
- symfony/framework-bundle: ^6.4 || ^7.1
- symfony/phpunit-bridge: ^7.1
- symfony/security-bundle: ^6.4 || ^7.1
- symfony/twig-bundle: ^6.4 || ^7.1
- zenstruck/foundry: ^2.0
Conflicts
- gedmo/doctrine-extensions: <3.11
- sonata-project/admin-bundle: <4.25
- dev-master / 0.20.x-dev
- 0.20.0
- 0.19.1
- 0.19.0
- 0.18.0
- 0.17.2
- 0.17.1
- 0.17.0
- 0.16.1
- 0.16.0
- 0.15.7
- v0.15.6
- v0.15.5
- v0.15.4
- v0.15.3
- v0.15.2
- v0.15.1
- v0.15.0
- v0.14.1
- v0.14.0
- v0.13.3
- v0.13.2
- v0.13.1
- v0.13.0
- v0.12.0
- v0.11.1
- v0.11.0
- v0.10.3
- v0.10.2
- v0.10.1
- v0.10.0
- 0.9.3
- 0.9.2
- 0.9.1
- 0.9.0
- v0.8.2
- v0.8.1
- v0.8.0
- v0.7.1
- v0.7.0
- v0.6.9
- v0.6.8
- v0.6.7
- v0.6.6
- v0.6.5
- v0.6.4
- v0.6.3
- v0.6.2
- v0.6.1
- v0.6.0
- v0.5.0
- v0.4.1
- v0.4.0
- v0.3.1
- 0.3.0
- 0.2.1
- 0.2.0
- 0.1.1
- 0.1.0
This package is auto-updated.
Last update: 2024-10-21 11:46:34 UTC
README
This bundle gives the ability to define sortable entities and to be able to sort the using Sonata Backoffice. It is inspired on: pixSortableBehaviorBundle.
Installation
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
composer require runroom-packages/sortable-behavior-bundle
Enable the Bundle
Then, enable the bundle by adding it to the list of registered bundles in config/bundles.php
file of your project:
// config/bundles.php return [ // ... Runroom\SortableBehaviorBundle\RunroomSortableBehaviorBundle::class => ['all' => true], ];
Usage
This bundle checks if you are using Gedmo Sortable to handle the sort order of your entities, if not, it will use the default ORM implementation, where you will need to add entities on the configuration of the bundle manually. If you are using Gedmo, and don't want to change the default field name position
, you don't need to configure anything for the bundle.
We provide a trait, so you can easily add the position field with the Gedmo configuration on each entity you want to be able to sort:
# src/Entity/Example.php namespace App\Entity; use Runroom\SortableBehaviorBundle\Behaviors\Sortable; class Example { use Sortable; // ... rest of your class }
And then, on your admin class, you can add the SortableAdminTrait
trait to be able to sort the entities on the list view:
# src/Admin/ExampleAdmin.php namespace App\Admin; use Runroom\SortableBehaviorBundle\Admin\SortableAdminTrait; use Sonata\AdminBundle\Admin\AbstractAdmin; use Sonata\AdminBundle\Datagrid\ListMapper; class ExampleAdmin extends AbstractAdmin { use SortableAdminTrait; protected function configureListFields(ListMapper $list): void { $list // ... rest of your list fields ->add(ListMapper::NAME_ACTIONS, ListMapper::TYPE_ACTIONS, [ 'actions' => [ // ... rest of your actions 'move' => [ 'template' => '@RunroomSortableBehavior/sort.html.twig', ], ], ]); } }
And that's all, you should now see the sort buttons on the list view of your admin class.
Configuration
# config/packages/runroom_sortable_behavior.yaml runroom_sortable_behavior: # position_handler can be any service id that implements the PositionHandlerInterface position_handler: Runroom\SortableBehaviorBundle\Service\GedmoPositionHandler # or Runroom\SortableBehaviorBundle\Service\ORMPositionHandler if gedmo is not found position_field: default: position # Default field name for the position # Only needed when not using Gedmo entities: App\Entity\Foobar: order App\Entity\Baz: rang # Only needed when not using Gedmo sortable_groups: entities: App\Entity\Baz: [group]
Use a draggable list instead of up/down buttons
In order to use a draggable list instead of up/down buttons, change the template in the move
action to @RunroomSortableBehavior/sort_drag_drop.html.twig
.
protected function configureListFields(ListMapper $list): void { $list // ... rest of your list fields ->add(ListMapper::NAME_ACTIONS, ListMapper::TYPE_ACTIONS, [ 'actions' => [ // ... rest of your actions 'move' => [ 'template' => '@RunroomSortableBehavior/sort_drag_drop.html.twig', 'enable_top_bottom_buttons' => true, // optional ], ], ]); }
Contribute
The sources of this package are contained in the Runroom monorepo. We welcome contributions for this package on runroom/runroom-packages.
License
This bundle is under the MIT license.