Skip to content

Commit ed935bb

Browse files
committed
Merge personalisation WordList into Grid 3
Process WordList items attached to a page (from personalisation) and merge them into the existing Grid.WordList.Items.WordListItem array. Checks for a known symbol key ('wordListItems'), handles casing variations of existing items, ensures an array, and appends new items in Grid 3 format (Text.p.s.r, Image as '', PartOfSpeech 'Unknown'). Skips processing if there is no existing WordList.Items to avoid creating new cells.
1 parent 6b7a7d2 commit ed935bb

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

src/processors/gridsetProcessor.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2760,6 +2760,40 @@ class GridsetProcessor extends BaseProcessor {
27602760
}
27612761
}
27622762

2763+
// Process WordList items attached to the page (from personalisation)
2764+
// These are tracked separately and shouldn't create new cells
2765+
// Use a known symbol key to check for WordList items
2766+
const WORDLIST_ITEMS_KEY = 'wordListItems';
2767+
const wordListItems = (page as any)[WORDLIST_ITEMS_KEY] as
2768+
| Array<{ label: string; message: string }>
2769+
| undefined;
2770+
2771+
if (wordListItems && wordListItems.length > 0 && originalGrid.Grid?.WordList?.Items) {
2772+
const existingItems =
2773+
originalGrid.Grid.WordList.Items.WordListItem ||
2774+
originalGrid.Grid.WordList.Items.wordlistitem ||
2775+
[];
2776+
const itemsArray = Array.isArray(existingItems) ? existingItems : [existingItems];
2777+
2778+
// Add new WordList items with proper Grid 3 format
2779+
for (const item of wordListItems) {
2780+
itemsArray.push({
2781+
Text: {
2782+
p: {
2783+
s: {
2784+
r: item.label,
2785+
},
2786+
},
2787+
},
2788+
Image: '',
2789+
PartOfSpeech: 'Unknown',
2790+
});
2791+
}
2792+
2793+
// Update the WordList
2794+
originalGrid.Grid.WordList.Items.WordListItem = itemsArray;
2795+
}
2796+
27632797
// Build the updated grid XML and format for Grid 3 compatibility
27642798
let builtXml = gridBuilder.build(originalGrid);
27652799
builtXml = formatGrid3XmlComplete(builtXml);

0 commit comments

Comments
 (0)