Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions addon/serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,25 @@ const DrupalJSONAPISerializer = JSONAPISerializer.extend({
},

modelNameFromPayloadKey(key) {
let parts = key.split('--');
const parts = key.split('--');
if (parts.length === 2) {
let bundle = parts[1];
return singularize(normalizeModelName(bundle));
const entity = parts[0];
const bundle = parts[1];
return this.get('drupalMapper').modelNameFor(entity, bundle) || singularize(normalizeModelName(bundle));
}
return singularize(normalizeModelName(key));
},

payloadKeyFromModelName(modelName) {
const drupalMapper = this.get('drupalMapper');
if (drupalMapper.isMapped(modelName)) {
const entity = drupalMapper.entityFor(modelName);
const bundle = drupalMapper.bundleFor(modelName);
return `${entity}--${bundle}`;
}
return modelName;
},

extractAttributes(modelClass, resourceHash) {
let modelClassString = modelClass.toString(),
modelName = modelClassString.split(':')[1],
Expand Down
16 changes: 16 additions & 0 deletions addon/services/drupal-mapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,21 @@ export default Service.extend({
return DRUPAL_FIELD_PREFIX + underscore(fieldName);
}
return underscore(fieldName);
},

isMapped(modelName) {
return this.map.hasOwnProperty(modelName);
},

modelNameFor(entity, bundle) {
return Object.keys(this.map).find(modelName => {
const modelMap = this.map[modelName];
modelMap.entity = modelMap.entity || 'node';

const bundleMatches = modelMap.bundle === bundle || modelMap.bundle === undefined && modelName === bundle;
if (bundleMatches && modelMap.entity === entity) {
return true;
}
});
}
});