Skip to content

Commit

Permalink
added field mapper to REST block
Browse files Browse the repository at this point in the history
  • Loading branch information
danielwirz committed Jan 11, 2021
1 parent a6c27e2 commit 2de8fdc
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
(function ($) {
$(document).on('iq-progressive-decoupler-after-init', function (e) {
Object.keys(drupalSettings.progressive_decoupler).forEach(function(blockId){
var $target = $('#' + blockId).find('[data-target]');
var template = Twig.twig({data: drupalSettings.progressive_decoupler[blockId].template});
var pattern = drupalSettings.progressive_decoupler[blockId].ui_pattern;
$.get(drupalSettings.progressive_decoupler[blockId].api_endpoint, function(response){
let blockData = drupalSettings.progressive_decoupler[blockId];
let $target = $('#' + blockId).find('[data-target]');
let template = Twig.twig({data: blockData.template});
let pattern = blockData.ui_pattern;
$.get(blockData.api_endpoint, function(response){
response.forEach(function(item){
var $item = $(template.render(item));
let fieldMapper = new iq_progessive_decoupler_FieldMapper(item, blockData.field_mapping);
let $item = $(template.render(fieldMapper.applyMappging()));
$(document).trigger('iq-progressive-decoupler-after-item-rendered[' + pattern + ']', $item);
$target.append($item);
});
Expand Down

0 comments on commit 2de8fdc

Please sign in to comment.