function SimplenewsSourceNode::getAttachments in Simplenews 7
Implements SimplenewsSourceInterface::getAttachments().
Overrides SimplenewsSourceInterface::getAttachments
File
- includes/
simplenews.source.inc, line 805 - Contains SimplenewsSource interface and implementations.
Class
- SimplenewsSourceNode
- Simplenews source implementation based on nodes for a single subscriber.
Code
function getAttachments() {
if ($cache = $this->cache
->get('data', 'attachments')) {
return $cache;
}
$attachments = array();
$build = $this
->build();
$fids = array();
foreach (field_info_instances('node', $this->node->type) as $field_name => $field_instance) {
// @todo: Find a better way to support more field types.
// Only add fields of type file which are enabled for the current view
// mode as attachments.
$field = field_info_field($field_name);
if ($field['type'] == 'file' && isset($build[$field_name])) {
if ($items = field_get_items('node', $this->node, $field_name)) {
foreach ($items as $item) {
$fids[] = $item['fid'];
}
}
}
}
if (!empty($fids)) {
$attachments = file_load_multiple($fids);
}
$this->cache
->set('data', 'attachments', $attachments);
return $attachments;
}