Closed kyeno closed 3 years ago
So you added the sortable sniped to the user admin?
What would you expect, a normal user isn't sortable at all.
Uhhmmm... maybe I forgot to paste the a portion of my App\Entity\User
:
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Validator\Constraints as Assert;
use Sonata\UserBundle\Entity\BaseUser as BaseUser;
...cut
/**
* User
*
* @ORM\Table(name="fos_user")
* @ORM\Entity(repositoryClass="App\Repository\UserRepository")
*/
class User extends BaseUser
{
... cut
/**
* @var int $position
*
* Display position on the team page
* @ORM\Column(name="position", type="integer", length=3)
* @Gedmo\SortablePosition
*/
private $position;
... cut
}
It actually doesn't matter if it's sortable here.
What does matter is that the template's object
refers to BaseUser
and not User
Entity.
Here is tutorial how to make it step by step (I using it). If you cant reproduce it one to one then we have issue. Otherwise you should be able to modify this code to own usage.
https://symfony.com/doc/current/bundles/SonataAdminBundle/cookbook/recipe_sortable_listing.html
Also check where is your template:
Admin/_sort.html.twig
should be in templates/Admin/_sort.html.twig
@App/Admin_sort.html.twig
should be in src/Resources/views/Admin/_sort.html.twig
@wbloszyk I have followed that guide precisely. Works like a charm for any other entities except extended User
entity, since then that problem appears.
My template loads properly, it is in templates/Admin/_sort.html.twig
, I just copied and slightly modified the original Pix's sortable one but definitely not in a manner that could break anything (simple HTML modifications; core references to object
remained the same).
Give it a try yourself:
$position
to your User entity@kyeno I checked it. It is not ower issue. You should create it in pixassociates/sortable-behavior-bundle
.
Problem is here (after remove it all is OK): https://github.com/pix-digital/pixSortableBehaviorBundle/blob/master/Services/PositionORMHandler.php#L49-L60
Ha! You're right. Thank you!
@kyeno I didnt follow everything, but should some doc be improved ?
@VincentLanglet Nope. In fact it's a bug in another bundle. Sonata is good. 👍
Sonata packages
Symfony packages
PHP version
Subject
When trying to integrate PixSortableBehaviorBundle with SonataUserBundle, so I can freely move users around (they're displayed on a subpage), things crash.
Analyzing deeper, it actually treats the
object
Entity within custom template asBaseUser
, and not as my extendedUser
class.My
sonata_user.yaml
config:Part of my
listMapper
from my customApp\Admin\UserAdmin.php
Crashing contents of
Admin/_sort.html.twig
template:Steps to reproduce
Enable custom Twig template within
_actions
array in ListMapper, and refer toobject
within that template.Expected results
object
being representation ofApp\Entity\User
, notSonata\UserBundle\Entity\BaseUser
NOTE: It works perfectly on any other, hand-made Entities not extending SonataUserBundle.
Actual results
An exception has been thrown during the rendering of a template ("[Semantical Error] line 0, col 13 near 'position) as': Error: Class Sonata\UserBundle\Entity\BaseUser has no field or association named position").