/** * 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; }
/** * Sets an item. * * @param Yosymfony\Spress\Core\DataSource\ItemInterface * * @throws \RuntimeException If the item has been registered previously in another collection */ public function set(ItemInterface $item) { $id = $item->getId(); $collectionName = $item->getCollection(); $this->items[$id] = $item; if (isset($this->idCollections[$id]) && $this->idCollections[$id] !== $collectionName) { throw new \RuntimeException(sprintf('The item with id: "%s" has been registered previously with another collection.', $id)); } if (isset($this->itemCollections[$collectionName]) === false) { $this->itemCollections[$collectionName] = []; } $this->itemCollections[$collectionName][$id] = $item; $this->idCollections[$id] = $collectionName; }
private function processDraftIfPost(ItemInterface $item) { $attributes = array_replace(['draft' => false], $item->getAttributes()); if (is_bool($attributes['draft']) === false) { throw new AttributeValueException('Invalid value. Expected boolean.', 'draft', $item->getPath(ItemInterface::SNAPSHOT_PATH_RELATIVE)); } if ($item->getCollection() === 'posts' && $attributes['draft'] === true) { if ($this->processDraft === false) { $attributes['output'] = false; $item->setAttributes($attributes); } } }
private function isCustomCollection(ItemInterface $item) { return !in_array($item->getCollection(), ['posts', 'pages']); }
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; }