Пример #1
0
 /**
  * Return the URL to display a given preview
  * @param string $token as received from Prismic server to identify the content to preview
  * @param \Prismic\LinkResolver $linkResolver the link resolver to build URL for your site
  * @param string $defaultUrl the URL to default to return if the preview doesn't correspond to a document
  *                (usually the home page of your site)
  * @return string the URL you should redirect the user to preview the requested change
  */
 public function previewSession($token, $linkResolver, $defaultUrl)
 {
     $response = $this->getHttpAdapter()->get($token);
     $response = json_decode($response->getBody(true));
     if (isset($response->mainDocument)) {
         $documents = $this->forms()->everything->query(Predicates::at("document.id", $response->mainDocument))->ref($token)->submit()->getResults();
         if (count($documents) > 0) {
             return $linkResolver->resolveDocument($documents[0]);
         }
     }
     return $defaultUrl;
 }
Пример #2
0
 /**
  * Return the URL to display a given preview
  * @param string $token as received from Prismic server to identify the content to preview
  * @param \Prismic\LinkResolver $linkResolver the link resolver to build URL for your site
  * @param string $defaultUrl the URL to default to return if the preview doesn't correspond to a document
  *                (usually the home page of your site)
  * @return string the URL you should redirect the user to preview the requested change
  */
 public function previewSession($token, $linkResolver, $defaultUrl)
 {
     $response = $this->getHttpClient()->get($token);
     $response = json_decode($response->getBody(true));
     if (isset($response->mainDocument)) {
         $documents = $this->query(Predicates::at("document.id", $response->mainDocument), ['ref' => $token])->getResults();
         if (count($documents) > 0) {
             if ($url = $linkResolver->resolveDocument($documents[0])) {
                 return $url;
             }
         }
     }
     return $defaultUrl;
 }