protected function normalize(Collection $collection) { $data = []; foreach ($collection as $entity) { $normalized = $this->normalizer->normalize($entity); $description = $normalized->getMetadata()->getDescription(); try { $description = $this->renderService->render($description); } catch (RuntimeException $e) { // nothing to do } $authors = $entity->getRevisions()->map(function ($revision) { return $revision->getAuthor()->getId(); }); $description = $this->descriptionFilter->filter($description); $item = ['title' => $normalized->getTitle(), 'description' => $description, 'guid' => (string) $entity->getId(), 'keywords' => $normalized->getMetadata()->getKeywords(), 'categories' => $this->getCategories($entity), 'link' => $this->url()->fromRoute($normalized->getRouteName(), $normalized->getRouteParams()), 'lastModified' => $normalized->getMetadata()->getLastModified(), 'authorsCount' => count(array_unique($authors->toArray())), 'revisionsCount' => $entity->getRevisions()->count()]; $data[] = $item; } return $data; }
/** * {@inheritDoc} */ public function toDocument($object) { if (!$object instanceof EntityInterface) { throw new InvalidArgumentException(sprintf('Expected TaxonomyTermInterface but got %s', is_object($object) ? get_class($object) : gettype($object))); } $normalized = $this->normalizer->normalize($object); $id = $object->getId(); $instance = $object->getInstance()->getId(); $title = $normalized->getTitle(); $content = $normalized->getContent(); $keywords = $normalized->getMetadata()->getKeywords(); $type = $object->getType()->getName(); $link = $this->router->assemble($normalized->getRouteParams(), ['name' => $normalized->getRouteName()]); try { $content = $this->renderService->render($content); } catch (RuntimeException $e) { // Could not render -> nothing to do. } $content = $this->stripTags->filter($content); return new Document($id, $title, $content, $type, $link, $keywords, $instance); }