3

Is there any way to get all fields attached to an entity in D8 (including widget types), using REST services? I've tried the following endpoints, but none of them had the list of fields:

/entity/node_type/{node_type}
/entity/entity_form_display/{entity_form_display}
/entity/entity_form_mode/{entity_form_mode}

I need this if for an app that will generate dynamic forms, based on what's defined in the Drupal backend.

  • 1
    Interesting, we might be able to use configuration schema to get the fields definition. However we don't have REST endpoint in core – vijaycs85 Jul 5 '15 at 20:24
1

The /entity/entity_form_display/{entity_form_display} should works.

Example:

/entity/entity_form_display/node.article.default?_format=json

It will return json like this:

{
"uuid": "058dd73d-366d-466d-9393-ad0d5d44e928",
"langcode": "en",
"status": true,
"dependencies": {
    "config": [
        "field.field.node.article.body",
        "field.field.node.article.comment",
        "field.field.node.article.field_image",
        "field.field.node.article.field_location",
        "field.field.node.article.field_tags",
        "image.style.thumbnail",
        "node.type.article"
    ],
    "module": [
        "comment",
        "image",
        "path",
        "text"
    ]
},
"id": "node.article.default",
"targetEntityType": "node",
"bundle": "article",
"mode": "default",
"content": {
    "body": {
        "type": "text_textarea_with_summary",
        "weight": 1,
        "region": "content",
        "settings": {
            "rows": 9,
            "summary_rows": 3,
            "placeholder": ""
        },
        "third_party_settings": []
    },
    "comment": {
        "type": "comment_default",
        "weight": 20,
        "region": "content",
        "settings": [],
        "third_party_settings": []
    },
    "created": {
        "type": "datetime_timestamp",
        "weight": 10,
        "region": "content",
        "settings": [],
        "third_party_settings": []
    },
    "field_image": {
        "type": "image_image",
        "weight": 4,
        "region": "content",
        "settings": {
            "progress_indicator": "throbber",
            "preview_image_style": "thumbnail"
        },
        "third_party_settings": []
    },
    "field_location": {
        "weight": 121,
        "settings": [],
        "third_party_settings": [],
        "type": "options_select",
        "region": "content"
    },
    "field_tags": {
        "type": "entity_reference_autocomplete_tags",
        "weight": 3,
        "region": "content",
        "settings": {
            "match_operator": "CONTAINS",
            "size": 60,
            "placeholder": ""
        },
        "third_party_settings": []
    },
    "path": {
        "type": "path",
        "weight": 30,
        "region": "content",
        "settings": [],
        "third_party_settings": []
    },
    "promote": {
        "type": "boolean_checkbox",
        "settings": {
            "display_label": true
        },
        "weight": 15,
        "region": "content",
        "third_party_settings": []
    },
    "status": {
        "type": "boolean_checkbox",
        "settings": {
            "display_label": true
        },
        "weight": 120,
        "region": "content",
        "third_party_settings": []
    },
    "sticky": {
        "type": "boolean_checkbox",
        "settings": {
            "display_label": true
        },
        "weight": 16,
        "region": "content",
        "third_party_settings": []
    },
    "title": {
        "type": "string_textfield",
        "weight": 0,
        "region": "content",
        "settings": {
            "size": 60,
            "placeholder": ""
        },
        "third_party_settings": []
    },
    "uid": {
        "type": "entity_reference_autocomplete",
        "weight": 5,
        "region": "content",
        "settings": {
            "match_operator": "CONTAINS",
            "size": 60,
            "placeholder": ""
        },
        "third_party_settings": []
    }
},
"hidden": []
}
  • it seems giving out the administer node form display permission is required. this sounds like a security issue if all you're trying to do is build forms dynamically for any user? – E.A.T Apr 22 at 3:04
0

You have to define your own endpoint to implement this, core does not offer this information.

  • Do you know contrib/custom modules that do this? It seems a general purpose module. – jcisio Nov 20 '15 at 10:36
0

You can access bundle definitions via and export with https://www.drupal.org/project/bundle_copy. This could be modified or permissions could be used to access them from a client-side app or static generator.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.