Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
As multiple file upload is not possible in IMCE, I would like to add the possibilty to unzip a zip file in IMCE.
So I'm creating a module to do this.
I want to add a new button, like the delete button, and when user click on it, a confirm box appears before unzip the selected file.
The problem is that my button doesn't appears in IMCE interface.
Here is the code in my module to add the unzip button :
function imce_unzip_form(&$form_state, $ref) {
$imce =& $ref['imce'];
$formUnzip['unzip'] = array(
'#type' => 'submit',
'#value' => t('Unzip'),
'#submit' => $imce['perm']['unzip'] ? array('imce_unzip_submit') : NULL,//permission for submission
);
if (imce_perm_exists($imce, 'unzip')) {
$form['fset_unzip'] = array(
'#type' => 'fieldset',
'#title' => t('Unzip'),
) + $formUnzip;
}
$form['#action'] = $imce['url'];
return $form;
}
and in my js file (my js script file is well loaded in firebug ) :
imce.hooks.load.push (function () {
imce.opAdd({name: 'unzip', title: Drupal.t('Unzip'), func: imce.unzipOpSubmit});
});
Is it the good way to add a new button in IMCE interface ?
Comment | File | Size | Author |
---|---|---|---|
#10 | imce_unzip.zip | 13.74 KB | elopez69 |
#9 | imce_unzip.zip | 13.17 KB | lucuhb |
#6 | imce_unzip.zip | 12.91 KB | lucuhb |
#5 | imce_unzip.zip | 12.58 KB | lucuhb |
Comments
Comment #1
ufku CreditAttribution: ufku commentedSee IMCE Crop as an example for adding a new file operation.
Comment #2
lucuhb CreditAttribution: lucuhb commentedThanks for your response.
Like in imce_crop, I had the hook_imce_form_alter, like this :
The Unzip button appears now. In the implementation here, a new container-inline section is added with a submit button.When I click on this button, nothing appends and nothing in my log. Yet I added this part in my module :
I have tried to had this in my imce_unzip.file, but this doesn't work :
So somebody have an idea why nothing appends ?
In addition I would like a confirm window appears rather than the div container-inline. How to do this ?
Comment #3
ufku CreditAttribution: ufku commentedYou call _imce_unzip_file_unzip() with filepath but it seems to expect an object.
imce_unzip_form_validate is unnecessary.
You should implement imce_js_unzip for ajax callbacks
Comment #4
lucuhb CreditAttribution: lucuhb commentedok, you are right, the _imce_unzip_file_unzip want an objet (I didn't care about this because there is nothing at all when I click on the 'Unzip' button), so I changed this.
I suppressed the imce_unzip_form_validate function (and its reference in imce_unzip_form) and added the imce_js_unzip function like this :
Unfortunatly nothing works more when I click ti the second button 'Unzip'.
In firebug, I don't see the imce_unzip.js in the script tab : it seems not to be load in imce. Is there something else to load the js file in imce ?
Comment #5
lucuhb CreditAttribution: lucuhb commentedThe module I wanted to develop is now functional: it allows to add unzip functionality to IMCE.
You can get the module in attached file and try it. If someone sees some problems, don't hesitate to give me some returns.
thanks!
Comment #6
lucuhb CreditAttribution: lucuhb commentedThere was a problem of permission when the user navigates on directory. The version in the attached file corrects this problem.
Comment #7
Hadrien KOHL CreditAttribution: Hadrien KOHL commentedWorks nice with me !!!
You should release it as a module.
Thanks.
Comment #8
nateB CreditAttribution: nateB commentedNice stuff. Subscribing!
Comment #9
lucuhb CreditAttribution: lucuhb commentedWhen the zip archive was created with a mac computer, a directory __MACOSX was created in the zip. Here is a new version of the module that do not extract this directory and files in it.
Comment #10
elopez69 CreditAttribution: elopez69 commentedThanks for this code!!!
I found some problems. Only one level of subdirectories was working for me. The 2nd level, 3th, and.. so on were no created and the files inside the subdirectories goes to the directory where the zip file is located. I made some changes to fix it and I'm posting the new code. I hope the author agree with them
Comment #11
juanjo_vlc CreditAttribution: juanjo_vlc commentedI'll test it when i go back to work on monday.
I think it must be integrated into IMCE module because it is a very important feature.
I propose it to be included on IMCE module ¿anyone supports me?
Comment #12
ufku CreditAttribution: ufku commentedClosing 6.x-1.x issues as this branch is no more supported.
OTH, this zip functionality can be contributed as a separate module like imce_crop.
Comment #13
steve.colson CreditAttribution: steve.colson commentedI have created a project for this over here: http://drupal.org/sandbox/stephen.colson/1322504
I have fixed some bugs and brought it up to the Drupal Coding standards so far as coder is concerned. Hopefully in the next few days it gets approved as an actual module!