I'm creating a HTTP RESTful API plugin for Craft. In this case, I'm trying to return Elements (based on criteria), and include their content (via $element->getContent()
).
By default, if I return just the Elements collection returned by craft()->elements->getCriteria($type)->find()
, the content is not included.
I'm also running each Element through a Transformer which uses ModelHelper::packageAttributeValue($value)
, and converts attributes to their proper PHP type using attribute configs.
I'm not sure the best way to go about including content in my responses dynamically. Suggestions?
Edit:
I've just found out that $element->getContent()
returns fields that aren't even associated with that particular element. Weird. Anybody know anything about this? I've instead resorted to using:
$fields = array_map(function (FieldLayoutFieldModel $model) {
return $model->getField();
}, $element->getFieldLayout()->getFields());
Not sure what's best here.