I am building a feed using Element API. I am currently looping through Matrix blocks to get various data (based on the help from this post). One of the matrix blocks contains a Super Table field, with various fields inside of that. Here is the relevant section of my Element API config file.
'transformer' => function(Entry $entry) {
$contentBlocksArray = [];
foreach ($entry->contentBlocks as $block){
switch($block->type->handle) {
case 'introText':
$contentBlocksArray[] = [
'introText' => [
'body' => $block->body,
]
];
break;
case 'twoColumnText':
$contentBlocksArray[] = [
'twoColumnText' => [
'columnTextBlocks' => [
'icon' => $block->icon,
'text' => $block->text
]
]
];
break;
The first case in this switch works as expected. 'introText' is the Matrix box and 'body' is a plaintext field inside that block. The second case is where I'm having trouble. 'twoColumnText' is the Matrix block and 'columnTextBlocks' is a Super Table field with two plaintext fields. The api returns a response, but both 'icon' and 'text' = null.
I have also tried calling some of the functions as demonstrated in Super Tables docs here but no luck. I am by no means a php / laravel / etc developer, so I might be missing something that would be obvious to such a developer.
I suspect it's something similar to retrieving images where I have to loop through the Super Table fields, but I don't know what that syntax would look like.
$block->columnTextBlocks->icon
? If it's not a static field I can create an answer with how to loop through the rows