phpsymfonysulu

sulu CMS admin ui not showing data


i'm trying display the list from the controller, all the routes are loading but the data is not displaying


    #[Route(path: '/admin/api/products', methods: ['GET'], name: 'app.get_products')]
    public function index(ManagerRegistry $doctrine): Response
    {
        $products = $doctrine->getRepository(Product::class)->findAll();   

        if (!$products) {
            return $this->json('No product found');
        }

        $data = [
            '_embedded' => [
                'products' => $products
            ]
        ];
   
        return $this->json($data);
    }

enter image description here

<?xml version="1.0" ?>
<list xmlns="http://schemas.sulu.io/list-builder/list">
    <key>products</key>
    <properties>
        <property name="id" visibility="no" translation="sulu_admin.id">
            <field-name>id</field-name>
            <entity-name>App\Entity\Product</entity-name>
        </property>

        <property name="Product" visibility="always" searchability="yes" type="string">
            <field-name>Product</field-name>
            <entity-name>App\Entity\Product</entity-name>
        </property>
        
        <property name="item_number" visibility="always" type="string">
            <field-name>ItemNumber</field-name>
            <entity-name>App\Entity\Product</entity-name>
        </property>

        <property name="quantity" visibility="always" type="integer">
            <field-name>quantity</field-name>
            <entity-name>App\Entity\Product</entity-name>
        </property>
    </properties>
</list>

I tried to use DoctrineRepresentational factory but shows undefined.

Is there something that I'm missing?


Solution

  • You might want to check the Sulu Workshop repository and step through the different Pull Requests to follow along. That helped me when developing my first custom entities: https://github.com/sulu/sulu-workshop/pulls

    For example, the Sulu people use a custom DoctrineListRepresentationFactory class which returns a PaginatedRepresentation via a DoctrineListBuilder. I would assume your code does not work because the JSON response does not match what Sulu Admin is expecting.