Totally possible. Just loop through the blocks and add whatever data you want from them to the response array:
'transformer' => function(EntryModel $entry) {
// Create an array of all the "Body" Matrix field's blocks
$bodyBlocks = [];
foreach ($entry->body as $block) {
switch ($block->type->handle) {
case 'text':
$bodyBlocks[] = [
'text' => $block->myRichTextField->getParsedContent(),
];
break;
case 'image':
$image = $block->myAssetsField->first();
$bodyBlocks[] = [
'image' => $image ? $image->getUrl(['width' => 500]),
'caption' => $block->myPlainTextField,
];
break;
}
}
return [
'title' => $entry->title,
'url' => $entry->url,
'description' => (string) $entry->description,
'body' => $bodyBlocks
];
},
Each of the elements in that sub-array will be MatrixBlockModel objects.
'text' => $block->text,to my endpoint def returnsProperty 'Craft\MatrixBlockModel.text' is not defined.. My handle istextfor a rich text field. – Paulo Jan 06 '16 at 22:59textfield. – Brandon Kelly Jan 06 '16 at 23:22textBlocktype has atextfield inside it (which is "rich text" but that shouldn't matter). I also have a few more with various fieldtypes inside of them. E.G.imageBlockhas an assets field inside of it but I haven't tried grabbing it yet. Trying to sort our the basics. Thanks a ton for your help with this! – Paulo Jan 06 '16 at 23:37getParsedConent()method, which was added in Craft 2.5.2753. – Brandon Kelly Jan 07 '16 at 11:41