Below is my code to output the news entires under the "news" section of my site using the Element API. My question is how do I output the matrix block with a block type of "text" with a field called "blockText"?
<?php
namespace Craft;
return [
'endpoints' => [
'api/entries' => [
'elementType' => 'Entry',
'criteria' => ['section' => 'news'],
'transformer' => function(EntryModel $entry) {
// Check to see if there are any images
$featuredImage = $entry->featuredImage->first();
$bodyBlocks = [];
foreach ($entry->bodyEnhanced as $block) {
switch ($block->type->handle) {
case 'text':
$bodyBlocks[] = [
//'text' => $block->type->attributeConfigs,
'content' => $block->type->bodyText
];
break;
}
}
return [
'id' => $entry->id,
'url' => $entry->url,
'postDate' => $entry->postDate,
'title' => $entry->title,
'excerpt' => !empty($entry->excerpt) ? $entry->excerpt : false,
'image' => !empty($featuredImage) ? $featuredImage->url : false,
'body' => $bodyBlocks,
];
}
],
],
];
This is the only line that is breaking my JSON. Any help would be greatly appreciated.
'content' => $block->type->bodyText