/** * 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; }
/** * Collection matching of a item. * * @return \Yosymfony\Spress\Core\ContentManager\Collection\CollectionInterface */ public function getCollectionForItem(ItemInterface $item) { foreach ($this->colectionItemCollection as $name => $collection) { $itemPath = $item->getPath(ItemInterface::SNAPSHOT_PATH_RELATIVE) . '/'; $collectionPath = $collection->getPath() . '/'; if (strpos($itemPath, $collectionPath) === 0) { return $collection; } } return $this->colectionItemCollection->get('pages'); }
protected function isWritable(ItemInterface $item) { return $item->getPath(ItemInterface::SNAPSHOT_PATH_RELATIVE_AFTER_CONVERT) === '' ? false : true; }
private function isRenderizerExcluded(ItemInterface $item) { $attributes = $item->getAttributes(); if (array_key_exists('avoid_renderizer', $attributes) === false) { return false; } if (is_bool($attributes['avoid_renderizer']) === false) { throw new AttributeValueException('Invalid value. Expected bolean.', 'avoid_renderizer', $item->getPath(ItemInterface::SNAPSHOT_PATH_RELATIVE)); } return $attributes['avoid_renderizer']; }
/** * 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); }
private function getPermalinkAttribute(ItemInterface $item) { $attributes = $item->getAttributes(); $permalink = isset($attributes['permalink']) ? $attributes['permalink'] : $this->defaultPermalink; if (is_string($permalink) === false) { throw new AttributeValueException('Invalid value. Expected string.', 'permalink', $item->getPath(ItemInterface::SNAPSHOT_PATH_RELATIVE)); } if (trim($permalink) === '') { throw new AttributeValueException('Invalid value. Expected a non-empty value.', 'permalink', $item->getPath(ItemInterface::SNAPSHOT_PATH_RELATIVE)); } return $permalink; }
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; }