Skip to content

Commit

Permalink
#17. Add entity_assemble_data() for comment update resource, it was o…
Browse files Browse the repository at this point in the history
…nce deprecated.
  • Loading branch information
signalpoint committed Feb 16, 2015
1 parent 1f435d2 commit ba800f3
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions src/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,3 +387,54 @@ function entity_types() {
catch (error) { console.log('entity_types - ' + error); }
}

/**
* Assembles the data string used in Service calls.
* @param {String} entity_type
* @param {String} bundle
* @param {Object} entity
* @param {Object} options
* @return {String} data
*/
function entity_assemble_data(entity_type, bundle, entity, options) {
try {
// @TODO - this is an old function that was once deprecated, however the
// Services module appears to require a application/x-www-form-urlencoded
// content type when using PUT via the Comment Update resource, so we need
// this function to generate the URL encoded string.
var data = '';
for (var property in entity) {
if (entity.hasOwnProperty(property)) {
var type = typeof entity[property];
// Assemble field items.
if (type === 'object') {
for (var language in entity[property]) {
if (entity[property].hasOwnProperty(language)) {
for (var delta in entity[property][language]) {
if (entity[property][language].hasOwnProperty(delta)) {
for (var value in entity[property][language][delta]) {
if (
entity[property][language][delta].hasOwnProperty(value)) {
data += property +
'[' + language + '][' + delta + '][' + value + ']=' +
encodeURIComponent(
entity[property][language][delta][value]
) + '&';
}
}
}
}
}
}
}
// Assemble flat properties.
else {
data += property + '=' + encodeURIComponent(entity[property]) + '&';
}
}
}
if (data != '') { data = data.substring(0, data.length - 1); }
return data;
}
catch (error) { console.log('entity_assemble_data - ' + error); }
}

0 comments on commit ba800f3

Please sign in to comment.