Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Body now showing if default language is not "und" (undefined) #239

Closed
quiquee opened this issue Apr 5, 2014 · 9 comments
Closed

Body now showing if default language is not "und" (undefined) #239

quiquee opened this issue Apr 5, 2014 · 9 comments
Labels

Comments

@quiquee
Copy link
Contributor

quiquee commented Apr 5, 2014

My website has french as default language.

The service delivers content tagged by language , but for some reason the content appears under "und" in the response (undefined)

This was supposed to be fixed in the service module some time ago, so I am trying to reopen it. In the meantime, I think it would be good practice to be safe and show the content under "und" if there is no content in the node language.

For an example point here:
http://www.padelfirst.com/?q=drupalgap/node/2.json

@signalpoint
Copy link
Owner

@quiquee Yes, the entire multi-lingual features of DrupalGap core need some attention. I've only ever had to support English, so I haven't had the opportunity (or multi lingual capabilities myself) to thoroughly test this.

I see from your example URL that the language code of the node is 'fr', but all the field's on the node have their language code set to 'und'. If you've reopened/submitted an issue for that with Services, will you please post it here.

From my recollection, DrupalGap looks to the entity's language code, then tries to use that to render the fields on the entity using that language code. I don't know if it is checking for a null language code, then falling back to und.

To help DrupalGap accommodate this potential mismatch of language codes. I'd essentially use grep to look for the word 'language' anywhere in the source code:

cd /var/www/drupal-7/mobile-application/src
grep -rn 'language' .

That'll reveal the majority of the places that need to be taken into consideration. I think I'd start with the drupalgap_entity_render_content function, and somewhere in there (and/or before/after) we need to check for null/undefined on the entity's language code (e.g. fr), and if it isn't present, fall back to und.

@quiquee
Copy link
Contributor Author

quiquee commented Apr 5, 2014

Yep, sounds good , I already grepped through the code and landed in that
particular function. I will give it a deep dive and try to implement a
workaround.
The issue that was tracking this in the services module is
https://drupal.org/node/1668422

Thanks

On Sat, Apr 5, 2014 at 5:54 PM, Tyler Frankenstein <[email protected]

wrote:

@quiquee https://github.com/quiquee Yes, the entire multi-lingual
features of DrupalGap core need some attention. I've only ever had to
support English, so I haven't had the opportunity (or multi lingual
capabilities myself) to thoroughly test this.

I see from your example URL that the language code of the node is 'fr',
but all the field's on the node have their language code set to 'und'. If
you've reopened/submitted an issue for that with Services, will you please
post it here.

From my recollection, DrupalGap looks to the entity's language code, then
tries to use that to render the fields on the entity using that language
code. I don't know if it is checking for a null language code, then falling
back to und.

To help DrupalGap accommodate this potential mismatch of language codes.
I'd essentially use grep to look for the word 'language' anywhere in the
source code:

cd /var/www/drupal-7/mobile-application/src
grep -rn 'language' .

That'll reveal the majority of the places that need to be taken into
consideration. I think I'd start with the drupalgap_entity_render_content
function, and somewhere in there (and/or before/after) we need to check for
null/undefined on the entity's language code (e.g. fr), and if it isn't
present, fall back to und.

Reply to this email directly or view it on GitHubhttps://github.com//issues/239#issuecomment-39642096
.

@signalpoint
Copy link
Owner

@quiquee Was the node in question created with DrupalGap?

If so, it may be DrupalGap improperly setting the language code on the fields when it does the POST.

Set debug to true in settings.js, try creating a node from the app, and watch the console.log().

You'll see the JSON object it sends to the server. Does it set the language property on the node, and fields, or does it just ignore it and use 'und' only on the fields?

@quiquee
Copy link
Contributor Author

quiquee commented Apr 5, 2014

No the node was not created with DrupalGap. I am having problems to log in from ripple and it doesnt look that it is linked to cross-domain scripting. It looks more like if the login response is not yet loaded when the postprocess hook is called.
This is the line that fails in

// drupalgap.js:8222
var response = JSON.parse(result.responseText); 

The error is:

200 - OK jdrupal-7.x-1.0-rc2.min.js:23
POST: http://localhost/?q=drupalgap/user/login.json jdrupal-7.x-1.0-rc2.min.js:22
200 - OK jdrupal-7.x-1.0-rc2.min.js:23
user_services_postprocess - SyntaxError: Unexpected token u drupalgap.js:8222
POST: http://localhost/?q=drupalgap/system/connect.json jdrupal-7.x-1.0-rc2.min.js:22
200 - OK jdrupal-7.x-1.0-rc2.min.js:23

I tried using a proxy locally and as well running all from the same machine. The issue is always the same with ripple for something that works ok when tested in a device or in the emulator. Any help or clue for debugging would be greatly welcome.

Thank you

@signalpoint
Copy link
Owner

@quiquee In user_services_postprocess(), I'd recommend doing this:

dpm(result);
var response = JSON.parse(result.responseText);

And then look around in the response object that is printed to the console.

The post process hook shouldn't be invoked until after the user login post is complete, so I'm not quite sure what is happening there.

I usually disable the "Cross Domain Proxy" in Ripple for localhost, and haven't had any login problems.

You may have to launch chrome from a terminal with the disable security flag if connecting to a remote site:

http://www.drupalgap.org/node/223

@quiquee
Copy link
Contributor Author

quiquee commented Apr 6, 2014

I can't see the output of dpm(result) as there is no result.responseText in
the response so it returns before the dpm.
Rest of the services work ok. Maybe the problem is with the sessid and the
usage of proxy to access the server where services run.

if (!result.responseText) { return;}
dpm(result);
var response = JSON.parse(result.responseText);

I checked the result object with dpm and I dont see anything like
responseText in it, so I am puzzled. The user object stays undefined after
what it looks a succesful login. As everything works ok in a device (but the "und" issue) I will try to debug from there and let you know
Thank you !

@quiquee
Copy link
Contributor Author

quiquee commented Apr 13, 2014

I have now ripple working correctly and I can develop locally and mirror changes to my server. Things are now much easier.

The issue was that the content of the node didnt show.
I have put this in my drupalgap.js for now. Obviously a dirty workaround for now

function node_page_view_pageshow(nid) {
  try {
    node_load(nid, {
        success: function(node) {
          // Build the node display.
          var body = node.content;
          // If the node.content is not populated ...
          // issue reported in https://github.com/signalpoint/DrupalGap/issues/239
          if (!body) {
            body = node.body.und[0].value;
          }
          var build = {
            'theme': 'node',
            // @todo - is this line of code doing anything?
            'node': node,
            // @todo - this is a core field and should by fetched from entity.js
            'title': {'markup': node.title},
            'content': {'markup': body}
          };

@jomarocas
Copy link

Hi @signalpoint you update this in a commit in drupalgap project in drupal.org? or how update this issue, i have same proble

@signalpoint
Copy link
Owner

@jomarocas Usually it is enough to just download the latest drupalgap.min.js file: http://drupalgap.org/download - there are more details here: http://docs.drupalgap.org/7/Install/Upgrading - other than that, following Drupal module update procedures (or downloading the latest dev snapshot of the DrupalGap module) will update everything on the Drupal site.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants