function gc_gc_process_files_field in GatherContent 8
Same name and namespace in other branches
- 8.3 gathercontent.module \gc_gc_process_files_field()
Parameters
EntityMetadataWrapper $node: Object of node.
string $local_field_name: Local field name.
string $gc_field_name: Name of field in GatherContent.
bool $is_translatable: Indicator if node is translatable.
string $language: Language of translation if applicable.
array $files: Array of remote files.
1 call to gc_gc_process_files_field()
File
- ./
gathercontent.module, line 502 - Main module file for GatherContent module.
Code
function gc_gc_process_files_field(EntityMetadataWrapper &$node, $local_field_name, $gc_field_name, $is_translatable = FALSE, $language = 'und', $files) {
$found_files = array();
foreach ($files as $file) {
if ($file->field === $gc_field_name) {
$found = FALSE;
foreach ($node->{$local_field_name}
->value() as $file) {
if ($file['gc_id'] === $file->id) {
$found = TRUE;
}
}
if (!$found) {
$local_file = file_save_data(file_get_contents($file->url), 'public://' . $file->filename);
$local_file->gc_id = $file->id;
file_save($local_file);
$found_files[] = array(
'fid' => $local_file->fid,
);
}
}
}
if ($is_translatable) {
$node
->language($language)->{$local_field_name} = $found_files;
}
else {
$node->{$local_field_name} = $found_files;
}
}