runroom / sortable-behavior-bundle
Installs: 7 033
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 7
Forks: 49
Open Issues: 0
Type:symfony-bundle
Requires
- php: ^7.3
- doctrine/common: ^2.12
- symfony/config: ^4.4 || ^5.0
- symfony/dependency-injection: ^4.4 || ^5.0
- symfony/http-foundation: ^4.4 || ^5.0
- symfony/http-kernel: ^4.4 || ^5.0
- symfony/property-access: ^4.4 || ^5.0
- symfony/translation: ^4.4 || ^5.0
- twig/twig: ^2.12 || ^3.0
Requires (Dev)
- doctrine/orm: ^2.7
- gedmo/doctrine-extensions: ^2.4
- sonata-project/admin-bundle: ^3.58
Suggests
- sonata-project/admin-bundle: Can be easily integrated with Sonata Admin bundle
- stof/doctrine-extensions-bundle: Manage doctrine extensions with Symfony
This package is auto-updated.
Last update: 2020-03-16 16:43:32 UTC
README
Offers a sortable feature for your Symfony admin listing
Configuration
By default, this extension works with Gedmo DoctrineExtensions, but you can change the position handler or implement your own (There are three implementations: Gedmo, ORM, and ODM):
# app/config/config.yml sortable_behavior: position_handler: sortable_behavior.position.orm position_field: default: sort # default value: position entities: AppBundle\Entity\Foobar: order AppBundle\Entity\Baz: rang sortable_groups: entities: AppBundle\Entity\Baz: [ group ]
Normal use
In order to use this bundle on sonata, you need to configure an action with a custom template.
<?php // ClientAdmin.php protected function configureListFields(ListMapper $listMapper) { $listMapper ->addIdentifier('name') ->add('enabled') ->add('_action', null, array( 'actions' => array( 'move' => array( 'template' => '@SortableBehavior/sort.html.twig', 'enable_top_bottom_buttons' => true, //optional ), ), )) ; }
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 @SortableBehavior/sort_drag_drop.html.twig
.
<?php // ClientAdmin.php protected function configureListFields(ListMapper $listMapper) { $listMapper ->addIdentifier('name') ->add('enabled') ->add('_action', null, array( 'actions' => array( 'move' => array( 'template' => '@SortableBehavior/sort_drag_drop.html.twig', 'enable_top_bottom_buttons' => true, // optional ), ), )) ; }
Also include the JavaScript needed for this to work, in your theme.yml
file, add these two lines:
//... javascripts: - bundles/sortablebehavior/js/jquery-ui.min.js // if you haven't got jQuery UI yet. - bundles/sortablebehavior/js/init.js
Adding the JavaScript and the template, will give you the possibility to drag items in a tablelist.
In case you need it, this plugin fires to jQuery events when dragging is done on the $(document)
element, so if you want to add custom notification, that is possible. Also, when dragging the <body>
gets an is-dragging
class. This class is removed when you stop dragging. This could by quite handy if you have some custom js/css.
SortableBehaviorBundle.success
SortableBehaviorBundle.error