prismicio-community / php-kit

Community maintained development kit for Prismic and the PHP language
https://prismic.io
Other
109 stars 83 forks source link

API query always uses master ref #116

Closed mbaxter91288 closed 7 years ago

mbaxter91288 commented 8 years ago

Hi,

Not sure if I'm missing something or not but I've been playing around with getting the preview functionality working and been digging into the code and looking at the query() function within Api.php line 432. It begins by trying to set the $ref and if it cannot find either the preview or experiment cookies it sets the master()->getRef(). But then in line 444 it doesn't use the above mentioned $ref it gets the master:

$form = $this->forms()->everything->ref($this->master()->getRef());

If I change the code (for testing only of course) to the below then my previewing works perfect.

$form = $this->forms()->everything->ref($ref);

Any help would be appreciated.

Regards, MAt

erwan commented 8 years ago

Hi,

The master ref is always the master, it's not the ref from the preview or experiment cookie. If you explicitly ask for the master, you won't get the preview or experiment ref.

Note that there is now a shortcut function that will automatically read the preview and experiment cookies:

https://github.com/prismicio/php-kit/blob/master/src/Prismic/Api.php#L423

mbaxter91288 commented 8 years ago

Thanks for responding.

I saw the shortcut function and this is what I was referring to. In lines 433 to 439 it sets a $ref variable either by cookie or falls back to master, but then in line 440 never uses it. I can't see what the $ref variable is used for if it wasn't meant to be used there :-/

erwan commented 8 years ago

Hey, that's correct, thank you for the heads up.

erwan commented 8 years ago

fixed: https://github.com/prismicio/php-kit/commit/6c98ad83d834f3be51d1b0f3ad393b55f000454a