1

I'm having issue with parent-child list view in symfony gedmo doctrine extensions. My list is showing everything in the same level and I don't know how to fix it. I've tried to use datagridvalues to sort by lftfield but it is not working.

My category.orm.yml file

Application\AdminBundle\Entity\Category:
  type: entity
  table: Category
  gedmo:
    tree:
      type: nested
  id:
    id:
      type: integer
      generator:
        strategy: AUTO
  fields:
    name:
      type: string
      length: 255
    image_url:
      type: string
      length: 255  
    slug:
      type: string
      nullable: false
      unique: true

    lft:
      type: integer
      gedmo:
        - treeLeft
    rgt:
      type: integer
      gedmo:
        - treeRight
    root:
      type: integer
      gedmo:
        - treeRoot
    lvl:
      type: integer
      gedmo:
        - treeLevel

  oneToMany:
    children:
      targetEntity: Category
      mappedBy: parent
  manyToOne:
    parent:
      targetEntity: Category
      inversedBy: children
      gedmo:
        - treeParent
      joinColumns:
        Category_id:
          referencedColumnName: id
  lifecycleCallbacks: {  }

And My configureListFields method:

protected function configureListFields(ListMapper $listMapper)
{

    $listMapper
    ->add('id')
    ->add('name')
    ->add('slug')
    ;
}

My list view looks like in image List view

woj_jas
  • 1,092
  • 7
  • 23
  • 50

1 Answers1

0

I was fighting with this too long ;)

I found in some codeproject's article that sonata admin is not supporting tree structures rendering (article was from 2012 so maybe something changed). Anyway my solution is preety simple

In my category.php i've added

public function __toString()
{
    $prefix = '';
    for ($i=1; $i<= $this->lvl; $i++){
        $prefix .= '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
    }
    return $prefix . $this->name;
}

public function getLaveledTitle()
{
    return (string)$this;
}

and in CategoryController.php in configureListFields method i've changed name field to

    $listMapper
     //if you will not add 'html' as field type `&nbsp` will not be parsed as html
    ->add('laveled_title', 'html', array(
            'strip' => true,
            'label' => 'Category Name'
    ))
    ;   
woj_jas
  • 1,092
  • 7
  • 23
  • 50