Snaptshots:
- raw: the uncompiled content of this item (not available for binary items).
- last: the most recent compiled content.
- after_convert: the compiled content after converter has been applied.
- after_render: the compiled content after renderizer has been applied.
public getContent ( $snapshotName = '' ) : string | ||
$snapshotName | The name of the snapshot. "last" by default | |
return | string | The content or empty-string If the snapshot does not exist |
/** * Gets the attributes of an item. * * @param ItemInterface $item * * @return array */ protected function getItemAttributes(ItemInterface $item) { $result = $item->getAttributes(); $result['id'] = $item->getId(); $result['content'] = $item->getContent(); $result['collection'] = $item->getCollection(); $result['path'] = $item->getPath(ItemInterface::SNAPSHOT_PATH_RELATIVE); return $result; }
private function convertItem(ItemInterface $item) { $this->eventDispatcher->dispatch('spress.before_convert', new Event\ContentEvent($item, ItemInterface::SNAPSHOT_RAW, ItemInterface::SNAPSHOT_PATH_RELATIVE)); $path = $item->getPath(ItemInterface::SNAPSHOT_PATH_RELATIVE); $ext = pathinfo($path, PATHINFO_EXTENSION); $result = $this->converterManager->convertContent($item->getContent(), $ext); $newPath = preg_replace('/\\.' . $ext . '$/', '.' . $result->getExtension(), $path); $item->setContent($result->getResult(), ItemInterface::SNAPSHOT_AFTER_CONVERT); $item->setPath($newPath, ItemInterface::SNAPSHOT_PATH_RELATIVE); $this->eventDispatcher->dispatch('spress.after_convert', new Event\ContentEvent($item, ItemInterface::SNAPSHOT_AFTER_CONVERT, ItemInterface::SNAPSHOT_PATH_RELATIVE)); $this->siteAttribute->setItem($item); }
/** * Converts an item. This method uses the SNAPSHOT_PATH_RELATIVE of Item path. * * @param Yosymfony\Spress\Core\DataSource\ItemInterface $item The item * * @return Yosymfony\Spress\Core\ContentManager\Converter\ConverterResult * * @throws RuntimeException If there's no converter for the extension passed */ public function convertItem(ItemInterface $item) { $path = $item->getPath(ItemInterface::SNAPSHOT_PATH_RELATIVE); $str = new StringWrapper($path); $extension = $str->getFirstEndMatch($this->textExtensions); if ($extension === '') { $extension = pathinfo($path, PATHINFO_EXTENSION); } return $this->convertContent($item->getContent(), $extension); }
protected function getItemAttributes(ItemInterface $item) { $result = $item->getAttributes(); $result['id'] = $item->getId(); $result['content'] = $item->getContent(); $result['collection'] = $item->getCollection(); $result['path'] = $item->getPath(ItemInterface::SNAPSHOT_PATH_RELATIVE); $result['relationships'] = []; $relationships = $item->getRelationshipCollection(); foreach ($relationships as $name => $items) { if (isset($result['relationships'][$name]) === false) { $result['relationships'][$name] = []; } foreach ($items as $relItem) { $relAttributes = $relItem->getAttributes(); $relAttributes['id'] = $relItem->getId(); $relAttributes['content'] = $relItem->getContent(); $relAttributes['collection'] = $relItem->getCollection(); $relAttributes['path'] = $relItem->getPath(ItemInterface::SNAPSHOT_PATH_RELATIVE); $result['relationships'][$name][] = $relAttributes; } } return $result; }