Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I'm creating a module which uses the Form API and integrates with the Mantis bugtracker system. I have included a managed file field on the form and am at the stage of handling the form submission. The Form API documentation mentions that you must make a call to file_usage_add:

Without the call to file_usage_add, file_managed_file_validate produces an error upon saving the form, saying that the uploaded file may not be referenced.

Here is the signature for file_usage_add():

file_usage_add(stdClass $file, $module, $type, $id, $count = 1)

And the explanation of the parameters:

$file: A file object.

$module: The name of the module using the file.

$type: The type of the object that contains the referenced file.

$id: The unique, numeric ID of the object containing the referenced file.

$count: (optional) The number of references to add to the object. Defaults to 1.

The problem I have is that my module doesn't create any nodes to attach the file to. I just want to store the file in the filesystem and then send it off to Mantis.

Any suggestions on what I can enter for the $type and $id parameters?

share|improve this question
    
What about attaching it to user 1? Are there any problems with this approach bearing in mind that there could be potentially quite a lot of files attached over time? –  littledynamo Mar 5 '13 at 10:31
    
Why a downvote?l –  littledynamo May 2 at 8:28
add comment

1 Answer 1

up vote 1 down vote accepted

I attached the file to user 1 and can't see any adverse effects as yet:

file_usage_add($file, 'mantis', 'user', 1);

I also OMITTED the following line from my submit function:

$file->status = FILE_STATUS_PERMANENT;

This means that the file will be deleted after 6 hours when cron runs.

If anyone has a better solution then I'll be happy to mark as answer.

share|improve this answer
    
I am also not sure how to handle the id on submit or import when the $node id is not available –  latvian May 1 at 21:32
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.