1

In a form I have added a field for images, set the file source to "Advanced upload widget (Plupload)" ( all other checkboxes are unchecked ) and I get the interface. I want to make it autoupload images after being drag and droped or selected via the add image link. The form is loaded in a custom created page using a personal made module. I tried to set

$form['field_image_article1']['#autoupload']=TRUE

in myModule_form_alter and also called a myModule_after_build. None of the situations work and I can't figure out where or better sayd when should I set this value. Here is the code for the module :

function add_new_article_menu() {
  $items['addAnnouncement'] = array(
  'title' => 'Adauga anunt',
  'page callback' => 'add_new_article_simple_page',
  'access callback' => TRUE,
  );
return $items;
}

function add_new_article_simple_page() {
form_load_include($form_state, 'inc', 'node', 'node.pages');
$node_form = new stdClass;
$node_form->type = 'announcement';
$node_form->language = LANGUAGE_NONE;
$form = drupal_get_form('announcement_node_form', $node_form);
return $form;
}
function add_new_article_form_alter(&$form, &$form_state, $form_id){
  if($form_id=='announcement_node_form'){
    $form['#after_build'][]='add_new_article_after_build';
    return $form;
  }
}
function add_new_article_after_build($form, &$form_state) {
  $form['field_image_article1']['#autoupload']=TRUE;
  return $form;
}

Modules installed for plupload : FileField Sources Plupload, File Field Sources , Plupload integration module

Any help is most appreciated.

0

Drupal's plupload module does not support '#autoupload'. Or at least that's what I experienced. I wrote my own behavior for this:

(function($) {

Drupal.plupload = Drupal.plupload || {};

/**
 * Attaches the Plupload behavior to each Plupload form element.
 */
Drupal.behaviors.mymodule_plupload = {
  attach: function (context, settings) {
    $(".plupload-element", context).once('mymodule-plupload-init', function () {
      var uploader = $(this).pluploadQueue();
      if(uploader !== undefined) {
        uploader.bind('FilesAdded', function(up, files) {
          $('.form-submit').prop( "disabled", true );
          uploader.start();
        });
        uploader.bind('UploadComplete', function() {
          if (uploader.files.length == (uploader.total.uploaded + uploader.total.failed)) {
            // If nothing is being uploaded right now:
            $('.form-submit').prop( "disabled", false );
          }
        });
      }
    });
  }
};

})(jQuery);

I based it on codes and hints from the Internet, but I can't recall exact sources. I'll be happy to fix that and add reference links if someone recognizes parts of this.

  • interesting, let me try it out. But yes, Drupal's plupload does suport autoupload : drupal.stackexchange.com/questions/87033/… . Problem is the solution is working if I programatically create it, but nobody seems to have any info on editing after load ... – Cristi Aug 19 '14 at 11:05
  • @Cristi it is said to support autoupload. I simply wasn't ever able to actually see it to do so and decided it will be easier to piece my own chunk of codes together. – Mołot Aug 19 '14 at 11:10
  • Oooh , I see. Regarding the code, are there any changes I need to make for it to work on my page? I made a js file with that code , edited mymodule with the actual name, checked if its loaded in page, but still doesn't work... – Cristi Aug 19 '14 at 11:16
  • Make sure your elements are correctly marked with plupload-element class, and if there are any errors in JS console - share. Oh, and consider adding some console.log to see if behavior is executed. Other than that? It should be generic enough. It does not contain anything related specifically to my site. – Mołot Aug 19 '14 at 11:19
  • the only field I have for images has a div with plupload-element class , nu js console errors . What do you mean by adding console.log ? – Cristi Aug 19 '14 at 11:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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