/** * Format field. * * @param array $field A field instance * @param FeedItem $item An entity instance * * @return XDOMElement */ protected function format($field, FeedItem $item) { $name = $field['name']; $method = $field['method']; $value = $item->{$method}(); if (isset($field['cdata'])) { $value = $this->dom->createCDATASection($value); $element = $this->dom->createElement($name); $element->appendChild($value); } elseif (isset($field['attribute'])) { $element = $this->dom->createElement($name); $element->setAttribute($field['attribute'], $item->getLink()); } else { if (isset($field['date_format'])) { $format = $field['date_format']; if (!$value instanceof \DateTime) { throw new \InvalidArgumentException(sprintf('Field "%s" should be a DateTime instance.', $name)); } $value = $value->format($format); } $element = $this->dom->createElement($name, $value); } return $element; }
/** * Preview an item that is already cached. * * @param FeedItem $feedItem The document FeedItem (retrieving for a ParamConverter with the id) * * @return string */ public function previewCachedAction(FeedItem $feedItem) { return $this->render('Api43FeedBundle:FeedItem:content.html.twig', array('title' => $feedItem->getTitle(), 'content' => $feedItem->getContent(), 'url' => $feedItem->getLink(), 'modal' => true)); }