I am attempting to create a custom source (see #2243589: Custom source fields not displayed for selected custom source for details), and after enabling my source in the field settings in the content type, I get an error that my process function can't be found, even though I have listed the file correctly in my filefield_sources_info hook implementation. I tracked this down to the following code in filefield_sources_field_process():
foreach ($sources as $source_name => $source) {
if (empty($enabled_sources[$source_name])) {
unset($sources[$source_name]);
}
else {
if (isset($source['process'])) {
$function = $source['process'];
$element = $function($element, $form_state, $form);
}
if (isset($source['file'])) {
_filefield_sources_form_include($source['module'], $source['file'], $form_state);
}
}
}
Basically, what it's doing is looking for the process function, and THEN including the file that is indicated in the $source['file'] value in the info hook. This doesn't seem to make much sense, since you need to include the file that contains the code before calling the function.
On a side note, I had also added my .inc file to the files() array in the module.info file, but for some reason that has no effect.
A patch is attached that simply includes the specified file before trying to call the function.
Comment | File | Size | Author |
---|---|---|---|
#1 | filefield-sources-include-file-first-2.patch | 1.57 KB | wonder95 |
filefield-sources-include-file-first.patch | 1.11 KB | wonder95 | |
Comments
Comment #1
wonder95 CreditAttribution: wonder95 commentedAfter a few hours trying to track down an error manifesting itself in Field Collection, I tracked it down to another case of this exact same issue in filefield_sources_field_value().
The error would be thrown when it tried to run $function[$element, $item), because at that point the external file had not been included.
An updated patch is attached.
Comment #2
wonder95 CreditAttribution: wonder95 commented