Publisher does not support the Fluid field type. Please do not contact asking when support will be available.
If you purchased an add-on from expressionengine.com, be sure to visit boldminded.com/claim to add the license to your account here on boldminded.com.
Ticket: MSM: can’t access translated content from site B from site A
Status | Resolved |
Add-on / Version | Publisher 1.4.0 |
Severity | Trivial |
EE Version | 2.8.1 |
Matt Stein
Jul 08, 2014Hi!
I’ve got JSON template that has one job: take an entry ID via URL segment and show its content. Two factors make this more interesting: a) the content can come from one of two sites (MSM), and b) tacking ‘/es’ or ‘/en’ onto the end of the request should determine whether it comes back in Spanish (when available) or English.
My template, which exists on and is called from site A (‘default_site’), looks like this:
[{exp:http_header status="200" content_type="application/json"}
{exp:channel:entries site="default_site|mobile" dynamic="no" channel="content" entry_id="{segment_3}" backspace="1"}
{
"title": {exp:json_encode}{title}{/exp:json_encode},
"lang": {exp:json_encode}{publisher:current_language_code}{/exp:json_encode},
"content_a": {exp:json_encode}{content_a}{/exp:json_encode}
},{/exp:channel:entries}]
When entry ID #22 is on site A, the following will happen as expected:
- http://foo.com/api/page-content/22: content is shown in English
- http://foo.com/api/page-content/22/en: content is shown in English
- http://foo.com/api/page-content/22/es: content is shown in Spanish (when available)
Now when entry #33 exists on site B (‘mobile’), the following happens:
- http://foo.com/api/page-content/33: content is shown in English
- http://foo.com/api/page-content/33/en: content is shown in English
- **http://foo.com/api/page-content/33/es: content is shown in English**
A Spanish translation is available for entry #33, and the “lang” property comes back with “es” as you might expect. If you navigate to site B, you’ll be able to switch languages just fine, and entry #33’s content will be presented in the selected language.
I can fix this if I explicitly set `site=“mobile”` in the template, instead of `site=“default_site|mobile”`, but then this little API can’t return any entries from site A. Removing `channel=“content”` has no affect. (Both example entries exist in channels called “content”.)
While I doubt it’s related to the problem, I’m pulling that last URL segment from EE’s config and using that to set `$config[‘publisher_lang_override’]`.
Is there a bug somewhere in Publisher’s handling (or ignoring) the `site` property of `exp:channel:entries`? Have I overlooked something glaringly obvious again?
- Matt
BoldMinded (Brian)
In models/publisher_entry.php add this var_dump and see what prints. My guess is its the default site_id?
https://www.evernote.com/shard/s9/sh/e6976699-7e46-4237-8fc2-5672533cd839/16715c7909a6ed23c627666f0f0fac74
Matt Stein
Wow, it’s kind of scary how fast you are! (Thanks!)
You’re correct, it’s a string with the default site ID:
string(1) "1"
.BoldMinded (Brian)
😊 Sometimes the reports just ring a bell and I have a pretty good idea what the issue is. The query isn’t taking into account multiple site_ids right now. I’ll try to get an update to you by the end of the week… maybe tonight if I find some time.
Matt Stein
Thanks Brian, I appreciate it. The end of the week would be fantastic if you have time. Cheers!
BoldMinded (Brian)
Matt, can you try something for me? Find this block of code around line 935 of publisher_entry.php
And remove the whole site_id line, and don’t forget the comma at the end of the previous line. It should look like this: https://www.evernote.com/shard/s9/sh/50cd7f9c-220b-46a8-a821-7754a0fb700e/b54ac0d0adeb8411f97a9a339b0ce0db
After looking at this again I don’t think the site_id parameter is required in my query, its using the entry_ids to find them, regardless of the site_id. Let me know if that works.
Matt Stein
That works great, thanks!