function _node_resource_load_node_files in Services 7.3
Same name and namespace in other branches
- 6.3 resources/node_resource.inc \_node_resource_load_node_files()
Generates an array of base64 encoded files attached to a node
Parameters
$nid: Number. Node ID
$include_file_contents: Bool Whether or not to include the base64_encoded version of the file.
$get_image_style: Bool Whether or not to provide image style paths.
Return value
Array. A list of all files from the given node
3 string references to '_node_resource_load_node_files'
- hook_services_resources in docs/
services.services.api.php - Defines function signatures for resources available to services.
- ServicesRESTServerTests::getTestResource in servers/
rest_server/ tests/ ServicesRESTServerTests.test - _node_resource_definition in resources/
node_resource.inc
File
- resources/
node_resource.inc, line 568
Code
function _node_resource_load_node_files($nid, $include_file_contents, $get_image_style) {
module_load_include('inc', 'services', 'resources/file_resource');
$node = node_load($nid);
// Hopefully theres another way to get a nodes fields that are a file, but this was the only way I could do it.
$fields = field_info_fields();
$files = array();
// Loop through all of the fields on the site
foreach ($fields as $key => $field) {
//if we are a field type of file
if ($field['type'] == 'image' || $field['type'] == 'file') {
// If this field exists on our current node..
if (isset($node->{$field['field_name']})) {
// If there are items in the field...
if (isset($node->{$field['field_name']}[LANGUAGE_NONE])) {
// Grab the items given and attach them to the array.
$node_file_field_items = $node->{$field['field_name']}[LANGUAGE_NONE];
foreach ($node_file_field_items as $file) {
$files[] = _file_resource_retrieve($file['fid'], $include_file_contents, $get_image_style);
}
}
}
}
}
return $files;
}