I'm using a Matrix field for menu section blocks that each have a name, section and menu items. The menu items for that menu section are assigned using an Entries fieldtype that displays entries from food and beverage entries. Here's a screenshot of the field setup in case that helps explain it better:
What I'm trying to do is generate a menu endpoint that has the individual sections and within each section display the item data. The json response I'm looking for should be similar to this structure:
"menu": {
"id": 1,
"sections": [
{
"id": 1,
"name": "Heavy",
"description": "All our heavy draft beers.",
"items": [
{
"id": 2,
"name": "Samuel Adams Utopias",
},
{
"id": 3,
"name": "Samuel Adams Utopias",
},
]
},
{
"id": 2,
"name": "Light",
"description": "All our light draft beers.",
"items": [
{
"id": 2,
"name": "Samuel Adams Utopias",
},
{
"id": 3,
"name": "Samuel Adams Utopias",
},
]
},
]
}
I can accomplish the section structure just fine, but I can't get the data from the sectionItems field which is an Entries type. This is what I have minus the items call.
'api/v1/locations/<entryId:\d+>/menu.json' => function($entryId) {
return [
'elementType' => 'Entry',
'criteria' => [
'id' => $entryId,
'type' => 'location'
],
'first' => true,
'transformer' => function(EntryModel $entry) {
foreach ($entry->menu as $block) {
$menuBlocks[] = [
'id' => $block->id,
'menu_id' => $block->fieldId,
'name' => $block->sectionName,
'description' => $block->sectionDescription,
'items' => $block->sectionItems,
];
}
return [
'title' => $entry->title,
'menu' => [
'sections' => $menuBlocks
]
];
},
];
},
Any help would be greatly appreciated!