Using the Element API, I want to return the values from checkboxes (the $block->product field). These checkboxes are within a matrix that I am already gathering data from. Currently am doing this:
return [
'endpoints' => [
'fullmembers.json' => [
'elementType' => 'User',
'criteria' => ['group' => 'fullMembership'],
'transformer' => function(UserModel $member) {
$businessCategories = [];
foreach ($member->businessTypeMarketSectorsProducts as $block) {
switch ($block->type->handle) {
case 'businessCategory':
$businessCategories[] = [
'businessType' => $block->businessType->value,
'marketSector' => $block->marketSector->value,
'product' => $block->product //Here you can see I'm calling the product field...
];
break;
}
}
return [
'id' => $member->id,
'companyName' => $member->membersCompanyName,
'addressLine3' => $member->membersAddressLine3,
'lat' => $member->memberAddress->lat,
'lng' => $member->memberAddress->lng,
'email' => $member->email,
// 'profile' => '/directory/company/' . $member->id . '/' . $member->username,
'profile' => UrlHelper::getUrl("directory/company/{$member->id}"),
'businessCategories' => $businessCategories
];
},
]
]
];
Here is a sample response:
{
"id": "1506",
"companyName": "Airsprung Group Plc",
"addressLine3": "",
"lat": "51.33188454",
"lng": "-2.20657303",
"email": "[email protected]",
"profile": "http:\/\/craft.fira\/directory\/company\/1506",
"businessCategories": [{
"businessType": "Manufacture",
"marketSector": "Domestic",
"product": {
"0": {
"label": "Beds",
"value": "Beds",
"selected": true
},
"1": {
"label": "Mattresses",
"value": "Mattresses",
"selected": true
},
"2": {
"label": "Seating \/ upholstery",
"value": "Seating \/ upholstery",
"selected": true
}
}
}, {
"businessType": "Manufacture",
"marketSector": "Contract",
"product": {
"0": {
"label": "Beds",
"value": "Beds",
"selected": true
},
"1": {
"label": "Mattresses",
"value": "Mattresses",
"selected": true
},
"2": {
"label": "Seating \/ upholstery",
"value": "Seating \/ upholstery",
"selected": true
}
}
}]
}
I would like the response to just show the values of the product checkboxes. Can you suggest a way to do this so that I am not returning the label and selected states? Ideally something like this:
"product": {"Beds", "Mattresses", "Seating \/ upholstery"}