Controller/FormController.php
public function cgetAction(Request $request)
    {
        $locale = $this->getLocale($request);
        $filters = $this->getFilters($request);

        // flatted entities
        if ('true' === $request->get('flat')) {
            /** @var RestHelperInterface $restHelper */
            $restHelper = $this->get('sulu_core.doctrine_rest_helper');

            /** @var DoctrineListBuilderFactory $factory */
            $factory = $this->get('sulu_core.doctrine_list_builder_factory');

            // get model class
            $listBuilder = $factory->create($this->getModelClass());

            // get fieldDescriptors
            $fieldDescriptors = $this->getFieldDescriptors($locale, $filters);
            $restHelper->initializeListBuilder($listBuilder, $fieldDescriptors);

            $listBuilder->addSelectField($fieldDescriptors['locale']);

            if ('true' !== $request->get('ghost')) {
                $listBuilder->where($fieldDescriptors['locale'], $locale);
            }

            // load entities
            $list = $listBuilder->execute();

            // get pagination
            $total = $listBuilder->count();
            $page = $listBuilder->getCurrentPage();
            $limit = $listBuilder->getLimit();
        } else {
            // load all entities by filters
            $list = $this->getManager()->findAll($locale, $filters);

            foreach ($list as $key => $entity) {
                $list[$key] = $this->getApiEntity($entity, $locale);
            }

            // get pagination
            $offset = $this->getOffset($filters);
            $limit = $this->getLimit($filters);
            $total = $offset + count($list);
            $page = $this->getPage($filters);

            // if to avoid db request with less items then the limit
            if (count($list) >= $limit) {
                $total = $this->getManager()->count($locale, $this->getCountFilters($filters));
            }
        }

        // create list representation
        $representation = new ListRepresentation(
            $list,
            $this->getListName(),
            $request->get('_route'),
            $request->query->all(),
            $page,
            $limit,
            $total
        );

        return $this->handleView($this->view($representation));
    }
public function cgetAction(Request $request)
    {
        $locale = $this->getLocale($request);
        $filters = $this->getFilters($request);

        // flatted entities
        if ('true' === $request->get('flat')) {
            /** @var RestHelperInterface $restHelper */
            $restHelper = $this->get('sulu_core.doctrine_rest_helper');

            /** @var DoctrineListBuilderFactory $factory */
            $factory = $this->get('sulu_core.doctrine_list_builder_factory');

            // get model class
            $listBuilder = $factory->create($this->getModelClass());

            // get fieldDescriptors
            $fieldDescriptors = $this->getFieldDescriptors($locale, $filters);
            $restHelper->initializeListBuilder($listBuilder, $fieldDescriptors);

            $listBuilder->addSelectField($fieldDescriptors['locale']);

            if ('true' !== $request->get('ghost')) {
                $listBuilder->where($fieldDescriptors['locale'], $locale);
            }

            // load entities
            $list = $listBuilder->execute();

            // get pagination
            $total = $listBuilder->count();
            $page = $listBuilder->getCurrentPage();
            $limit = $listBuilder->getLimit();
        } else {
            // load all entities by filters
            $list = $this->getManager()->findAll($locale, $filters);

            foreach ($list as $key => $entity) {
                $list[$key] = $this->getApiEntity($entity, $locale);
            }

            // get pagination
            $offset = $this->getOffset($filters);
            $limit = $this->getLimit($filters);
            $total = $offset + count($list);
            $page = $this->getPage($filters);

            // if to avoid db request with less items then the limit
            if (count($list) >= $limit) {
                $total = $this->getManager()->count($locale, $this->getCountFilters($filters));
            }
        }

        // create list representation
        $representation = new ListRepresentation(
            $list,
            $this->getListName(),
            $request->get('_route'),
            $request->query->all(),
            $page,
            $limit,
            $total
        );

        return $this->handleView($this->view($representation));
    }
@param Request $request

@return Response