According to this comment in the documentation, DrupalGap works with custom content types. However, when I visit the page node/add/mycustomcontenttype in the iOS simulator, I see "Undefined" on the page and the following messages in the console:

[Log] _drupalgap_form_render_elements - TypeError: undefined is not an object (evaluating 'drupalgap.field_info_extra_fields[f][c]') (console-via-logger.js, line 173)
[Log] node_add_page_by_type_title - TypeError: undefined is not an object (evaluating 'drupalgap.content_types_list[b].name') (console-via-logger.js, line 173)

Users have all permissions to edit, delete, and create the custom content type. This content type contains only a title and a body; it has no additional fields to get in the way.

I tried testing the built-in content types as well, which gave me no problems. When I click a link for the article content type (built-in, but customized with an image field and some other fields), everything shows up properly.

CommentFileSizeAuthor
#5 content_types_json.txt8.62 KBptmkenny
#5 edit_node_basic.jpg26.77 KBptmkenny
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tyler.frankenstein’s picture

Status: Active » Postponed (maintainer needs more info)

I'll need you to dig into _drupalgap_form_render_elements() and put a console.log(name); statement directly inside the $.each() loop.

From the output mentioned above, it looks like you're using the drupalgap.min.js, you'll need to switch to drupalgap.js and/or the makefile and src/.

That being said, this should work out of the box (for a 'und' language site). I wonder if we have a language code issue going on again. When iterating over the form elements in the $.each(), also keep an eye on the language code(s) being used, and see if that sheds any light.

ptmkenny’s picture

Yes, I do have a multilingual site. To eliminate potential errors caused by that, I temporarily removed all my custom code to change the site language and ensured that it was und at every step.

Then, I put console.log(name); in after the $.each() loop, and I visit my article content type, I get the following:

2015-04-16 23:05:18.979 Oh My Japan[78798:508707] nid
2015-04-16 23:05:18.979 Oh My Japan[78798:508707] title
2015-04-16 23:05:18.979 Oh My Japan[78798:508707] type
2015-04-16 23:05:18.979 Oh My Japan[78798:508707] language
2015-04-16 23:05:18.979 Oh My Japan[78798:508707] body
2015-04-16 23:05:18.980 Oh My Japan[78798:508707] field_tags
2015-04-16 23:05:18.980 Oh My Japan[78798:508707] field_image
2015-04-16 23:05:18.980 Oh My Japan[78798:508707] submit

When I visit my custom content type, I just get an error message:

2015-04-16 23:07:44.193 Oh My Japan[78798:508707] _drupalgap_form_render_elements - TypeError: undefined is not an object (evaluating 'drupalgap.field_info_extra_fields[bundle][name]')
2015-04-16 23:07:44.194 Oh My Japan[78798:508707] node_add_page_by_type_title - TypeError: undefined is not an object (evaluating 'drupalgap.content_types_list[type].name')

To try to debug further, I did a console.log(form), to capture the structure of my content type, which gave me the following:

{
    "arguments": [
        {
            "type": "simple"
        }
    ],
    "bundle": "simple",
    "buttons": {
        "cancel": {
            "attributes": {
                "onclick": "javascript:drupalgap_back();"
            },
            "title": "Cancel"
        }
    },
    "elements": {
        "language": {
            "default_value": "und",
            "id": "edit-node-edit-language",
            "is_field": false,
            "name": "language",
            "options": {
                "attributes": {
                    "id": "edit-node-edit-language"
                }
            },
            "required": true,
            "type": "hidden"
        },
        "nid": {
            "default_value": "",
            "id": "edit-node-edit-nid",
            "is_field": false,
            "name": "nid",
            "options": {
                "attributes": {
                    "id": "edit-node-edit-nid"
                }
            },
            "required": false,
            "type": "hidden"
        },
        "submit": {
            "id": "edit-node-edit-submit",
            "is_field": false,
            "name": "submit",
            "options": {
                "attributes": {
                    "id": "edit-node-edit-submit"
                }
            },
            "type": "submit",
            "value": "Save"
        },
        "title": {
            "default_value": "",
            "description": "",
            "id": "edit-node-edit-title",
            "is_field": false,
            "name": "title",
            "options": {
                "attributes": {
                    "id": "edit-node-edit-title"
                }
            },
            "required": true,
            "title": "Title",
            "type": "textfield"
        },
        "type": {
            "default_value": "simple",
            "id": "edit-node-edit-type",
            "is_field": false,
            "name": "type",
            "options": {
                "attributes": {
                    "id": "edit-node-edit-type"
                }
            },
            "required": true,
            "type": "hidden"
        }
    },
    "entity_type": "node",
    "id": "node_edit",
    "options": {
        "attributes": {
            "class": ""
        }
    },
    "prefix": "",
    "submit": [
        "node_edit_submit"
    ],
    "suffix": "",
    "validate": []
}

This is a "simple" content type I created that contains only the title and body (included by default) and no other custom fields.

ptmkenny’s picture

Status: Postponed (maintainer needs more info) » Active
tyler.frankenstein’s picture

Status: Active » Postponed (maintainer needs more info)

In _drupalgap_form_render_elements(), try replacing this:

        if (
              form.entity_type && bundle &&
              typeof drupalgap.field_info_extra_fields[bundle][name] !==
                'undefined' &&
              typeof
                drupalgap.field_info_extra_fields[bundle][name].weight !==
                'undefined'
            ) {

with this:

        if (
              form.entity_type && bundle &&
              typeof drupalgap.field_info_extra_fields[bundle] !== 'undefined' &&
              typeof drupalgap.field_info_extra_fields[bundle][name] !==
                'undefined' &&
              typeof
                drupalgap.field_info_extra_fields[bundle][name].weight !==
                'undefined'
            ) {

If I remember correctly, field_info_extra_fields is for things like title, nid, created, etc, so this could probably use that extra undefined check mentioned above, so multi lingual titles don't tweak out (not sure on this one though, but please try the code change).

Did you create this content type through the Drupal UI, or is it provided by a custom module?

As for the node_add_page_by_type_title() error, please do a:

console.log(drupalgap.content_types_list);

That way we can see what is up with your content type(s).

ptmkenny’s picture

Status: Postponed (maintainer needs more info) » Active
FileSize
26.77 KB
8.62 KB

Ok, I replaced the code as you suggested, and I now get the screen shown in the attached screenshot. The title is now editable, and there are options for save and cancel, so this is definitely progress (no more just "undefined").

Unfortunately, the "body" field still does not appear, nor does the title.

Now, about this content type, I made this content type in the UI. To create it, I named a new content type "Simple" and left all of the other settings at their default values.

In node_add_page_by_type_title(), I added console.log(drupalgap.content_types_list);, and the result was as attached (content_types_json.txt). Interestingly, all of my content types are listed *except* *Simple*, which is the only one created in the UI. (All other content types are provided by Core or defined in features).

So, I tried accessing my profile_pic content type in DrupalGap, which is a custom content type defined in a feature that includes an image field and a couple boolean checkboxes. When I viewed the edit screen for this content type, I got exactly the same output as for the "Simple" content type-- none of the additional fields that are attached to the content type were output, and there was no "Create Picture" title, either.