2017 © Pedro Peláez
 

symfony-bundle sortable-tree-bundle

Offers a sortable feature for your Symfony2/3 admin tree listing

image

mikeevstropov/sortable-tree-bundle

Offers a sortable feature for your Symfony2/3 admin tree listing

  • Wednesday, September 21, 2016
  • by mikeevstropov
  • Repository
  • 2 Watchers
  • 1 Stars
  • 9,750 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 4 Forks
  • 2 Open issues
  • 5 Versions
  • 21 % Grown

The README.md

Packagist, (*1)

mevSortableTreeBundle

Offers a sortable feature for your Symfony2/3 admin tree listing, (*2)

screenshot, (*3)

Install requirements

SonataAdminBundle
- the SonataAdminBundle provides a installation article here:
http://symfony.com/doc/current/cmf/tutorial/sonata-admin.html, (*4)

Install and enable Tree Extension from gedmo/doctrine-extensions
- nested behavior will implement the standard Nested-Set behavior on your Entity
(check stof/doctrine-extensions-bundle for easier integration in your project) https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/tree.md, (*5)

Installation

composer require mikeevstropov/sortable-tree-bundle

Configuration

Enable the mevSortableTreeBundle to your kernel:, (*6)

// app/AppKernel.php

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = [
            // ...
            new Mev\SortableTreeBundle\MevSortableTreeBundle(),
        ];
        // ...
    }
}

Include MevSortableTreeBundle:SortableTree to third service argument:, (*7)

``` yml, (*8)

app/config/services.yml

SonataAdminBundle Category

admin.category:
    class: AppBundle\Admin\CategoryAdmin
    arguments:
        - ~
        - AppBundle\Entity\Category
        - 'MevSortableTreeBundle:SortableTree'
    tags:
        - { name: sonata.admin, manager_type: orm, label: Category }

Create new routes and the action field in Admin Class: ```php // src/AppBundle/Admin/CategoryAdmin.php // ... use Sonata\AdminBundle\Route\RouteCollection; class CategoryAdmin extends AbstractAdmin { // ... protected function configureRoutes(RouteCollection $collection) { $collection->add('up', $this->getRouterIdParameter().'/up'); $collection->add('down', $this->getRouterIdParameter().'/down'); } protected function configureFormFields(FormMapper $formMapper) { // create custom query to hide the current element by `id` $subjectId = $this->getRoot()->getSubject()->getId(); $query = null; if ($subjectId) { $query = $this->modelManager ->getEntityManager('AppBundle\Entity\Category') ->createQueryBuilder('c') ->select('c') ->from('AppBundle:Category', 'c') ->where('c.id != '. $subjectId); } // ... $formMapper->add('parent', 'sonata_type_model', array( 'query' => $query, 'required' => false, // remove this row after the root element is created 'btn_add' => false, 'property' => 'name' )); } protected function configureListFields(ListMapper $listMapper) { // ... $listMapper->add('_action', null, array( 'actions' => array( 'up' => array( 'template' => 'MevSortableTreeBundle:Default:list__action_up.html.twig' ), 'down' => array( 'template' => 'MevSortableTreeBundle:Default:list__action_down.html.twig' ) ) )); } }

Configure sort the list of models by root and lft fields:, (*9)

// src/AppBundle/Admin/CategoryAdmin.php

// ...

class CategoryAdmin extends AbstractAdmin
{
    // ...
    public function createQuery($context = 'list')
    {
        $proxyQuery = parent::createQuery('list');
        // Default Alias is "o"
        // You can use `id` to hide root element
        // $proxyQuery->where('o.id != 1');
        $proxyQuery->addOrderBy('o.root', 'ASC');
        $proxyQuery->addOrderBy('o.lft', 'ASC');

        return $proxyQuery;
    }
    // ...
}

That's it!, (*10)

ToDo

  • Sortable behaveor for root elements (but, you can hide root element)

The Versions

21/09 2016

dev-master

9999999-dev https://github.com/mikeevstropov/mevSortableTreeBundle

Offers a sortable feature for your Symfony2/3 admin tree listing

  Sources   Download

MIT

The Requires

 

The Development Requires

by Mike Evstropov

symfony admin sonata tree sortable

09/08 2016

1.1.x-dev

1.1.9999999.9999999-dev https://github.com/mikeevstropov/mevSortableTreeBundle

Offers a sortable feature for your Symfony2/3 admin tree listing

  Sources   Download

MIT

The Requires

 

The Development Requires

by Mike Evstropov

symfony admin sonata tree sortable

09/08 2016

v1.1

1.1.0.0 https://github.com/mikeevstropov/mevSortableTreeBundle

Offers a sortable feature for your Symfony2/3 admin tree listing

  Sources   Download

MIT

The Requires

 

The Development Requires

by Mike Evstropov

symfony admin sonata tree sortable

16/07 2016

1.0.x-dev

1.0.9999999.9999999-dev https://github.com/mikeevstropov/mevSortableTreeBundle

Offers a sortable feature for your Symfony3 admin tree listing

  Sources   Download

MIT

The Requires

 

The Development Requires

by Mike Evstropov

admin sonata tree sortable

16/07 2016

v1.0

1.0.0.0 https://github.com/mikeevstropov/mevSortableTreeBundle

Offers a sortable feature for your Symfony3 admin tree listing

  Sources   Download

MIT

The Requires

 

The Development Requires

by Mike Evstropov

admin sonata tree sortable