Entity JS allows for Javascript layer access to some commonly used entity-related functions such as EntityFieldQuery.
This is achieved through Drupal menu callbacks and jQuery $.ajax calls.
Note: jQuery's jqXHR Object uses the .done()
method that requires later versions of jQuery (1.5+) than what currently ships with Drupal 7. In order to use these examples, we recommend installing jQuery Update. For more on .done()
, review the .promise() method jQuery API docs.
entity_create
Create an entity by providing a type and an array of arguments. Shown printing response below.
values = {
"name": "username",
"mail": "username@example.com",
}
entity_create('user', values).done(function(data) { console.log(data); });
Uses a $.post callback URL: /entity_create/[entity_type]
entity_render_view
Return a rendered entity using a view mode. Shown printing HTML to console below.
entity_render_view('node', 1, 'default').done(function(data) { console.log(data); });
Uses a $.get callback URL: /entity_js_drupal_render_entity_view/[entity_type]/[entity_id]/[view_mode]