/** * @param DocumentLink $link * * @return null|string */ public function resolve($link) { if ($link->isBroken()) { return null; } return "http://host/doc/" . $link->getId(); }
/** * Parses and extracts a link of absolutely any kind. * * @param \stdClass $data the json bit retrieved from the API that represents a Link fragment. * * @return \Prismic\Fragment\Link\LinkInterface the manipulable object for that Link fragment. */ public static function extractLink($data) { switch ($data->type) { case 'Link.web': return WebLink::parse($data->value); case 'Link.document': return DocumentLink::parse($data->value); case 'Link.file': return FileLink::parse($data->value); case 'Link.image': return ImageLink::parse($data->value); default: return null; } }
/** * @param DocumentLink $link * * @return string */ public function resolve($link) { return $this->urlGenerator->generate('detail', array('id' => $link->getId(), 'slug' => $link->getSlug())); }
/** * Parses a given fragment. For internal usage. * * @param \stdClass $json the json bit retrieved from the API that represents any fragment. * @return \Prismic\Fragment\FragmentInterface the manipulable object for that fragment. */ public static function parseFragment($json) { if (is_object($json) && property_exists($json, "type")) { if ($json->type === "Image") { $data = $json->value; $views = array(); foreach ($json->value->views as $key => $jsonView) { $views[$key] = ImageView::parse($jsonView); } $mainView = ImageView::parse($data->main, $views); return new Image($mainView, $views); } if ($json->type === "Color") { return new Color($json->value); } if ($json->type === "GeoPoint") { return new GeoPoint($json->value->latitude, $json->value->longitude); } if ($json->type === "Number") { return new Number($json->value); } if ($json->type === "Date") { return new Date($json->value); } if ($json->type === "Timestamp") { return new Timestamp($json->value); } if ($json->type === "Text") { return new Text($json->value); } if ($json->type === "Select") { return new Text($json->value); } if ($json->type === "Embed") { return Embed::parse($json->value); } if ($json->type === "Link.web") { return WebLink::parse($json->value); } if ($json->type === "Link.document") { return DocumentLink::parse($json->value); } if ($json->type === "Link.file") { return FileLink::parse($json->value); } if ($json->type === "Link.image") { return ImageLink::parse($json->value); } if ($json->type === "StructuredText") { return StructuredText::parse($json->value); } if ($json->type === "Group") { return Group::parse($json->value); } if ($json->type === "SliceZone") { return SliceZone::parse($json->value); } return null; } }
/** * Returns true if the given document link corresponds to the given bookmark * * @param API $api The API * @param DocumentLink $link The document link to test * @param string $bookmark The bookmark to test * * @return true if the given document corresponds to the given bookmark */ public function isBookmark($api, $link, $bookmark) { $maybeId = $api->bookmark($bookmark); if ($maybeId == $link->getId()) { return true; } return false; }
/** * Create Prismic specific Route Paramters from the given Document Link according to routing options * @param DocumentLink $link * @return array */ public function getRouteParams(DocumentLink $link) { $document = $this->getContext()->getDocumentById($link->getId()); $bookmark = $this->getContext()->findBookmarkByDocument($document); return array($this->routerOptions->getIdParam() => $link->getId(), $this->routerOptions->getUidParam() => $link->getUid(), $this->routerOptions->getMaskParam() => $document->getType(), $this->routerOptions->getBookmarkParam() => $bookmark, $this->routerOptions->getRefParam() => $this->getContext()->getRefAsString(), $this->routerOptions->getSlugParam() => $document->getSlug()); }