I have configured all, but I can't get work this bundle.
I can't see the buttons up/down
Here my ORM
AppBundle\Entity\SupvPageCategories:
type: entity
repositoryClass: Gedmo\Tree\Entity\Repository\NestedTreeRepository
table: supv_page_categories
gedmo:
tree:
type: nested
id:
pcId:
type: integer
nullable: false
options:
unsigned: false
id: true
column: pc_id
generator:
strategy: IDENTITY
fields:
pcCatname:
type: string
nullable: false
length: 100
options:
fixed: false
column: pc_catname
pcCattype:
type: string
nullable: false
length: 100
options:
fixed: false
column: pc_catType
lft:
type: integer
gedmo:
- treeLeft
rgt:
type: integer
gedmo:
- treeRight
lvl:
type: integer
gedmo:
- treeLevel
pcIsactive:
type: boolean
nullable: false
column: pc_isActive
pcUpdatedat:
type: datetime
nullable: true
column: pc_updatedAt
pcCreatedat:
type: datetime
nullable: false
column: pc_createdAt
manyToOne:
root:
targetEntity: AppBundle\Entity\SupvPageCategories
joinColumn:
referencedColumnName: pc_id
onDelete: CASCADE
gedmo:
- treeRoot
parent:
targetEntity: AppBundle\Entity\SupvPageCategories
inversedBy: children
joinColumn:
referencedColumnName: pc_id
onDelete: CASCADE
gedmo:
- treeParent
oneToMany:
children:
targetEntity: AppBundle\Entity\SupvPageCategories
mappedBy: parent
orderBy:
lft: ASC
lifecycleCallbacks: { }
Here my Entity
`<?php
namespace AppBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
/**
-
SupvPageCategories
/
class SupvPageCategories
{
/*
- @var int
*/
private $pcId;
/**
- @var string
*/
private $pcCatname;
/**
- @var string
*/
private $pcCattype;
/**
- @var bool
*/
private $pcIsactive;
/**
- @var \DateTime|null
*/
private $pcUpdatedat;
/**
- @var \DateTime
*/
private $pcCreatedat;
public function __construct()
{
$this->pcIsactive = true;
$this->pcCreatedat = new \DateTime();
$this->children = new ArrayCollection();
}
/**
- Get pcId.
- @return int
*/
public function getPcId()
{
return $this->pcId;
}
/**
/**
- Get pcCatname.
- @return string
*/
public function getPcCatname()
{
return $this->pcCatname;
}
/**
/**
- Get pcCattype.
- @return string
*/
public function getPcCattype()
{
return $this->pcCattype;
}
/**
/**
- Get pcIsactive.
- @return bool
*/
public function getPcIsactive()
{
return $this->pcIsactive;
}
/**
/**
- Get pcUpdatedat.
- @return \DateTime|null
*/
public function getPcUpdatedat()
{
return $this->pcUpdatedat;
}
/**
/**
- Get pcCreatedat.
- @return \DateTime
*/
public function getPcCreatedat()
{
return $this->pcCreatedat;
}
public function __toString()
{
if( is_null( $this->getPcCatname() ) ) {
return 'NULL';
}else{
return $this->getPcCatname();
}
}
/**
- @var \AppBundle\Entity\SupvPageCategories
*/
private $pcParentcat;
/**
-
Set pcParentcat.
-
@param \AppBundle\Entity\SupvPageCategories|null $pcParentcat
-
@return SupvPageCategories
*/
public function setPcParentcat(\AppBundle\Entity\SupvPageCategories $pcParentcat = null)
{
$this->pcParentcat = $pcParentcat;
return $this;
}
/**
- Get pcParentcat.
- @return \AppBundle\Entity\SupvPageCategories|null
/
public function getPcParentcat()
{
return $this->pcParentcat;
}
/*
- @var int
*/
private $lft;
/**
- @var int
*/
private $rgt;
/**
- @var int
*/
private $lvl;
/**
- @var \Doctrine\Common\Collections\Collection
*/
private $children;
/**
- @var \AppBundle\Entity\SupvPageCategories
*/
private $root;
/**
- @var \AppBundle\Entity\SupvPageCategories
*/
private $parent;
/**
/**
- Get lft.
- @return int
*/
public function getLft()
{
return $this->lft;
}
/**
/**
- Get rgt.
- @return int
*/
public function getRgt()
{
return $this->rgt;
}
/**
/**
- Get lvl.
- @return int
*/
public function getLvl()
{
return $this->lvl;
}
/**
/**
- Remove child.
- @param \AppBundle\Entity\SupvPageCategories $child
- @return boolean TRUE if this collection contained the specified element, FALSE otherwise.
*/
public function removeChild(\AppBundle\Entity\SupvPageCategories $child)
{
return $this->children->removeElement($child);
}
/**
- Get children.
- @return \Doctrine\Common\Collections\Collection
*/
public function getChildren()
{
return $this->children;
}
/**
/**
- Get root.
- @return \AppBundle\Entity\SupvPageCategories|null
*/
public function getRoot()
{
return $this->root;
}
/**
/**
- Get parent.
- @return \AppBundle\Entity\SupvPageCategories|null
*/
public function getParent()
{
return $this->parent;
}
}
`
And here my categoryAdmin
`<?php
// src/AppBundle/Admin/SupvPageCategoriesAdmin.php
namespace AppBundle\Admin;
use Sonata\AdminBundle\Route\RouteCollection;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Form\FormMapper;
class SupvPageCategoriesAdmin extends AbstractAdmin
{
protected $datagridValues = array(
'_sort_by' => 'pcCatname',
);
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()->getPcId();
$query = null;
if ($subjectId)
{
$query = $this->modelManager
->getEntityManager('AppBundle\Entity\SupvPageCategories')
->createQueryBuilder('c')
->select('c')
->from('AppBundle:SupvPageCategories', 'c')
->where('c.pcId != '. $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' => 'pcCatname'
))
->add('pcCatname', 'text');
}
protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
$datagridMapper->add('pcCatname');
}
protected function configureListFields(ListMapper $listMapper)
{
$listMapper->addIdentifier('pcCatname', 'text')
->addIdentifier('_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'
)
)
));
}
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;
}
}`
What I'm doing wrong?
I have configured all, but I can't get work this bundle.
I can't see the buttons up/down
Here my ORM
AppBundle\Entity\SupvPageCategories:
type: entity
repositoryClass: Gedmo\Tree\Entity\Repository\NestedTreeRepository
table: supv_page_categories
gedmo:
tree:
type: nested
id:
pcId:
type: integer
nullable: false
options:
unsigned: false
id: true
column: pc_id
generator:
strategy: IDENTITY
fields:
pcCatname:
type: string
nullable: false
length: 100
options:
fixed: false
column: pc_catname
pcCattype:
type: string
nullable: false
length: 100
options:
fixed: false
column: pc_catType
lft:
type: integer
gedmo:
- treeLeft
rgt:
type: integer
gedmo:
- treeRight
lvl:
type: integer
gedmo:
- treeLevel
pcIsactive:
type: boolean
nullable: false
column: pc_isActive
pcUpdatedat:
type: datetime
nullable: true
column: pc_updatedAt
pcCreatedat:
type: datetime
nullable: false
column: pc_createdAt
manyToOne:
root:
targetEntity: AppBundle\Entity\SupvPageCategories
joinColumn:
referencedColumnName: pc_id
onDelete: CASCADE
gedmo:
- treeRoot
parent:
targetEntity: AppBundle\Entity\SupvPageCategories
inversedBy: children
joinColumn:
referencedColumnName: pc_id
onDelete: CASCADE
gedmo:
- treeParent
oneToMany:
children:
targetEntity: AppBundle\Entity\SupvPageCategories
mappedBy: parent
orderBy:
lft: ASC
lifecycleCallbacks: { }
Here my Entity
`<?php
namespace AppBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
/**
SupvPageCategories
/
class SupvPageCategories
{
/*
*/
private $pcId;
/**
*/
private $pcCatname;
/**
*/
private $pcCattype;
/**
*/
private $pcIsactive;
/**
*/
private $pcUpdatedat;
/**
*/
private $pcCreatedat;
public function __construct()
{
$this->pcIsactive = true;
$this->pcCreatedat = new \DateTime();
$this->children = new ArrayCollection();
}
/**
*/
public function getPcId()
{
return $this->pcId;
}
/**
Set pcCatname.
@param string $pcCatname
@return SupvPageCategories
*/
public function setPcCatname($pcCatname)
{
$this->pcCatname = $pcCatname;
return $this;
}
/**
*/
public function getPcCatname()
{
return $this->pcCatname;
}
/**
Set pcCattype.
@param string $pcCattype
@return SupvPageCategories
*/
public function setPcCattype($pcCattype)
{
$this->pcCattype = $pcCattype;
return $this;
}
/**
*/
public function getPcCattype()
{
return $this->pcCattype;
}
/**
Set pcIsactive.
@param bool $pcIsactive
@return SupvPageCategories
*/
public function setPcIsactive($pcIsactive)
{
$this->pcIsactive = $pcIsactive;
return $this;
}
/**
*/
public function getPcIsactive()
{
return $this->pcIsactive;
}
/**
Set pcUpdatedat.
@param \DateTime|null $pcUpdatedat
@return SupvPageCategories
*/
public function setPcUpdatedat($pcUpdatedat = null)
{
$this->pcUpdatedat = $pcUpdatedat;
return $this;
}
/**
*/
public function getPcUpdatedat()
{
return $this->pcUpdatedat;
}
/**
Set pcCreatedat.
@param \DateTime $pcCreatedat
@return SupvPageCategories
*/
public function setPcCreatedat($pcCreatedat)
{
$this->pcCreatedat = $pcCreatedat;
return $this;
}
/**
*/
public function getPcCreatedat()
{
return $this->pcCreatedat;
}
public function __toString()
{
if( is_null( $this->getPcCatname() ) ) {
return 'NULL';
}else{
return $this->getPcCatname();
}
}
/**
*/
private $pcParentcat;
/**
Set pcParentcat.
@param \AppBundle\Entity\SupvPageCategories|null $pcParentcat
@return SupvPageCategories
*/
public function setPcParentcat(\AppBundle\Entity\SupvPageCategories $pcParentcat = null)
{
$this->pcParentcat = $pcParentcat;
return $this;
}
/**
/
public function getPcParentcat()
{
return $this->pcParentcat;
}
/*
*/
private $lft;
/**
*/
private $rgt;
/**
*/
private $lvl;
/**
*/
private $children;
/**
*/
private $root;
/**
*/
private $parent;
/**
Set lft.
@param int $lft
@return SupvPageCategories
*/
public function setLft($lft)
{
$this->lft = $lft;
return $this;
}
/**
*/
public function getLft()
{
return $this->lft;
}
/**
Set rgt.
@param int $rgt
@return SupvPageCategories
*/
public function setRgt($rgt)
{
$this->rgt = $rgt;
return $this;
}
/**
*/
public function getRgt()
{
return $this->rgt;
}
/**
Set lvl.
@param int $lvl
@return SupvPageCategories
*/
public function setLvl($lvl)
{
$this->lvl = $lvl;
return $this;
}
/**
*/
public function getLvl()
{
return $this->lvl;
}
/**
Add child.
@param \AppBundle\Entity\SupvPageCategories $child
@return SupvPageCategories
*/
public function addChild(\AppBundle\Entity\SupvPageCategories $child)
{
$this->children[] = $child;
return $this;
}
/**
*/
public function removeChild(\AppBundle\Entity\SupvPageCategories $child)
{
return $this->children->removeElement($child);
}
/**
*/
public function getChildren()
{
return $this->children;
}
/**
Set root.
@param \AppBundle\Entity\SupvPageCategories|null $root
@return SupvPageCategories
*/
public function setRoot(\AppBundle\Entity\SupvPageCategories $root = null)
{
$this->root = $root;
return $this;
}
/**
*/
public function getRoot()
{
return $this->root;
}
/**
Set parent.
@param \AppBundle\Entity\SupvPageCategories|null $parent
@return SupvPageCategories
*/
public function setParent(\AppBundle\Entity\SupvPageCategories $parent = null)
{
$this->parent = $parent;
return $this;
}
/**
*/
public function getParent()
{
return $this->parent;
}
}
`
And here my categoryAdmin
`<?php
// src/AppBundle/Admin/SupvPageCategoriesAdmin.php
namespace AppBundle\Admin;
use Sonata\AdminBundle\Route\RouteCollection;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Form\FormMapper;
class SupvPageCategoriesAdmin extends AbstractAdmin
{
}`
What I'm doing wrong?