Sulu\Bundle\MediaBundle\Controller\CollectionController::getAction PHP Method

getAction() public method

Shows a single collection with the given id.
public getAction ( $id, Request $request ) : Response
$id
$request Symfony\Component\HttpFoundation\Request
return Symfony\Component\HttpFoundation\Response
    public function getAction($id, Request $request)
    {
        if ($this->getBooleanRequestParameter($request, 'tree', false, false)) {
            $collections = $this->getCollectionManager()->getTreeById($id, $this->getRequestParameter($request, 'locale', true));
            if ($this->getBooleanRequestParameter($request, 'include-root', false, false)) {
                $collections = [new RootCollection($collections)];
            }
            return $this->handleView($this->view(new CollectionRepresentation($collections, 'collections')));
        }
        try {
            $locale = $this->getRequestParameter($request, 'locale', true);
            $depth = intval($request->get('depth', 0));
            $breadcrumb = $this->getBooleanRequestParameter($request, 'breadcrumb', false, false);
            $collectionManager = $this->getCollectionManager();
            // filter children
            $listRestHelper = $this->get('sulu_core.list_rest_helper');
            $limit = $request->get('limit', null);
            $offset = $this->getOffset($request, $limit);
            $search = $listRestHelper->getSearchPattern();
            $sortBy = $request->get('sortBy');
            $sortOrder = $request->get('sortOrder', 'ASC');
            $filter = ['limit' => $limit, 'offset' => $offset, 'search' => $search];
            $view = $this->responseGetById($id, function ($id) use($locale, $collectionManager, $depth, $breadcrumb, $filter, $sortBy, $sortOrder) {
                $collection = $collectionManager->getById($id, $locale, $depth, $breadcrumb, $filter, $sortBy !== null ? [$sortBy => $sortOrder] : []);
                if ($collection->getType()->getKey() === SystemCollectionManagerInterface::COLLECTION_TYPE) {
                    $this->get('sulu_security.security_checker')->checkPermission('sulu.media.system_collections', PermissionTypes::VIEW);
                }
                return $collection;
            });
        } catch (CollectionNotFoundException $cnf) {
            $view = $this->view($cnf->toArray(), 404);
        } catch (MediaException $e) {
            $view = $this->view($e->toArray(), 400);
        }
        return $this->handleView($view);
    }