Sort Gedmo Tree by arbitrary field using symfony3, doctrine2 and stofDoctrineExtensionsBundle

Introduction

Setting up

To setup Tree structure I used documentation on Symfony.com [2] followed by documentation on GitHub [3]. Then I proceeded with tree setup - used tree entity from example [4] and used code in [5] to create a tree.

I did setup the tree structure (that represents directories and files) called

FileTree

. I added several custom fields to the tree:

item_name

,

item_extension

and

is_file

. Removed

title

as I have

item_name

...

My

FileTree

entity:

<?php

namespace AppBundle\Entity;

use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\ManyToOne;
use Doctrine\ORM\Mapping\JoinColumn;
use Symfony\Component\Validator\Constraints as Assert;
use Doctrine\Common\Collections\ArrayCollection as ArrayCollection;