Exemplo n.º 1
0
 public function normalizeEntityCollection($entity, $rel, Pagerfanta $pager, FormDescription $formDescription)
 {
     $configurationEntityCollection = $this->getConfigurationEntityCollections()[$rel];
     if (isset($configurationEntityCollection['can_see']) && !$configurationEntityCollection['can_see']($this->securityContext, $entity)) {
         throw new AccessDeniedException();
     }
     $entityCollectionRepresentationClass = $configurationEntityCollection['representation_class'];
     $entityCollectionRepresentation = new $entityCollectionRepresentationClass();
     $this->configureCollectionRepresentation($entityCollectionRepresentation, $pager, $entity, $rel);
     // Results
     $entityCollectionRepresentation->results = array();
     foreach ($pager->getCurrentPageResults() as $entity) {
         $class = ClassUtils::getRealClass(get_class($entity));
         $entityResource = $this->container->get($configurationEntityCollection['resources'][$class]);
         $entityCollectionRepresentation->results[] = $entityResource->normalizeEntity($entity, true);
     }
     // Search form
     $entityCollectionRepresentation->addForm($this->formNormalizer->normalizeFormDescription($formDescription));
     return $entityCollectionRepresentation;
 }