Giter VIP home page Giter VIP logo

runroomsortablebehaviorbundle's Introduction

RunroomSortableBehaviorBundle

Latest Stable Version Latest Unstable Version License

Total Downloads Monthly Downloads Daily Downloads

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.

runroomsortablebehaviorbundle's People

Contributors

jenkins-runroom avatar jordisala1991 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.