Hi All, I've rethemed the image gallery module as described here http://drupal.org/node/41259 and it all works quite nicely many thanks to those contributers! (you can see my WIP at http://www.cust-art.com/gallery)

Now my question is I want to create a direct link to adding an image with a specific taxonomy already selected. (i.e. so that it goes to the create new image screen with a specific category selected for the vocabulary Image Galleries)

To explain further what I mean you can goto
http://www.cust-art.com/image/tid/17
(I've created a user which can see the admin controls but doesnt actually have editing access - username:testadmin, password:potato)
and under each gallery you will see an [add image] link (if you are logged in as testadmin). Currently I have these links as going to node/add/image?Image+Galleries=$gallery->tid
but it doesnt work (i wasnt surprised! it was just a shot in the dark.)

Does anyone have any idea how I can set the links so that they work?

cheers

Comments

mkabot68’s picture

I created a custom multi-picture upload form in my own module that mimics the image upload form and processing. May be of use, not sure.

inside hook_menu...

    $items[] = array('path'     => 'admin/pics',
                'title'         => t('Multiple Pictures'),
                'callback'      => '<modulename>_menu_pics',
                'access'        => user_access('Add Content'));

custom module functions


function <modulename>_menu_pics() {
  $content = "";

  if ($_POST['edit']['pics_many']) {
    $content .= _<modulename>_menu_pics_save();
  } else {
    $content .= _<modulename>_menu_pics_create();
  }

  // Output the page
  print theme("page", $content);
}

function _<modulename>_menu_pics_save() {
  global $user;

  // Start the return content
  $content = '<div id="message"><div class="messages status">';

  // Grab the Photo Album (term)
  $tid = $_POST['edit']['taxonomy'];

  // Loop through creating the nodes and adding Pictures
  // Go in reverse to get proper ordering
  for ($i=10; $i > 0; $i--) {
    // Create the array index
    $tag = "pic_" . $i;

    // Check the file
    $file = file_check_upload($tag);
    if (! $file) {
      continue;
    }

    // Create the node
    $node = new stdClass();
    $node->type = 'image';
    $node->uid = $user->uid;
    $timestamp = time();
    $node->created = $timestamp;
    $node->changed = $timestamp;
    $node->title = $file->filename;
    $node->teaser = "";
    $node->body = "";

    // Associate the Photo Album
    $node->taxonomy[] = $tid;
    // Set node behaviour
    $node->promote = 0;
    $node->status = 1;
    $node->format = 1;
    $node->sticky = 0;
    $node->revision = 0;
    $node->moderate = 0;
    $node->comment = 2;

    // Call image module to save file
    image_prepare($node,$tag);

    // Save the node
    $node->nid = node_save($node);

    // Clean up for next iteration
    unset($node);
  }

  $content .= "Upload Completed";

  $content .= "</div></div>";
  return $content;
}

function _<modulename>_menu_pics_create() {
  $content = "";

  // Figure out Photo Album vid
  $vocabs = taxonomy_get_vocabularies('image');
  foreach ($vocabs as $key => $value ) {
    $vid = $key;
  }

  // If there are no Photo Albums, send error
  if (! count(taxonomy_get_tree($vid))) {
        drupal_set_message(t('There are no Photo Albums to add Pictures to.<P>Please create an album first through the ') . l('Add Photo Album', 'admin/image/add') . ' screen first');
        return;
  }

  // Hidden field to flag form processing
  $form['pics_many'] = array(
      '#prefix' => 'Each uploaded picture must be less than ' . ini_get('upload_max_filesize') . 'B and the total of all pictures must be less than ' . ini_get('post_max_size') . 'B.',
      '#type' => 'hidden',
      '#default_value' => 1,
  );
  // Necessary for file upload
  $form['#attributes'] = array("enctype" => "multipart/form-data");

  // Select Photo Album (term)
  $form['taxonomy'] = taxonomy_form($vid);
  $form['taxonomy']['#title'] = t('Photo Album');
  $form['taxonomy']['#description'] = t('Select a Photo Album to add pictures to');

  // Do first file select to get label
  $form["pic_1"] = array(
      '#title' => 'Pictures',
      '#type' => 'file',
      '#size' => 40
    );
  // Select Files
  for ($i=2; $i<=10; $i++) {
    $form["pic_${i}"] = array(
      '#type' => 'file',
      '#size' => 40
    );
  }

  // Submit button
  $form['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Upload Pictures')
  );

  // Turn form into HTML
  $content .= drupal_get_form('_soar_menu_pics_many',$form);

  return $content;
}

high1memo’s picture

Hmmm, looks useful... though I don't think I can really use this to solve my problem.... but maybe for something else! Thanks anyways! :P

high1memo’s picture

Hi Boat daddy, now I need the exact same functionality that you have there! Uploading multiple images at once. I copied pasted your code into a module and uploaded, but I cannot see anything anywhere!? What am i doing wrong? or exactly what do i have to do with your code?