PHP code example of runroom-packages / sortable-behavior-bundle

1. Go to this page and download the library: Download runroom-packages/sortable-behavior-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

runroom-packages / sortable-behavior-bundle example snippets


// config/bundles.php

return [
    // ...
    Runroom\SortableBehaviorBundle\RunroomSortableBehaviorBundle::class => ['all' => true],
];

# src/Entity/Example.php

namespace App\Entity;

use Runroom\SortableBehaviorBundle\Behaviors\Sortable;

class Example
{
    use Sortable;
    // ... rest of your class
}

# 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',
                    ],
                ],
            ]);
    }
}

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
                ],
            ],
        ]);
}