You are here

function node_gallery_change_gallery_action_form in Node Gallery 6.3

Builds the form to allow a user to change the gallery of an image.

Parameters

$context:

Return value

A FAPI form array.

1 call to node_gallery_change_gallery_action_form()
node_gallery_form_alter in ./node_gallery.module
Implements hook_form_alter().

File

./node_gallery.actions.inc, line 174
Contains all actions for node gallery.

Code

function node_gallery_change_gallery_action_form($context = array()) {
  global $user;
  $i2g = node_gallery_get_image_to_gallery_types();
  static $user_gids = array();

  // We're being called from VBO - we can do extra validation
  if (!empty($context['view']) && $context['view']->plugin_name == 'bulk') {

    // Make sure that all the images selected have the same gallery type
    foreach ($context['selection'] as $node) {
      $nids[] = $node->nid;
    }
    $sql = "SELECT DISTINCT n.type FROM {node} n WHERE n.nid IN (" . db_placeholders($nids) . ")";
    $result = db_query($sql, $nids);
    $imagetypes = (array) node_gallery_get_types('image');
    $count = 0;
    while ($imagetype = db_fetch_array($result)) {
      $count++;
      if ($count > 1) {
        drupal_set_message(t('You must choose only node gallery images with the same gallery type when using the "Change parent gallery" action.'), 'error');
        return array();
      }
      if (in_array($imagetype['type'], $imagetypes)) {
        $gallery_type = $i2g[$imagetype['type']];
        $image_type = $imagetype['type'];
      }
      else {
        drupal_set_message(t('You must choose only node gallery images with the same gallery type when using the "Change parent gallery" action.'), 'error');
        return array();
      }
    }
  }
  else {
    if (isset($context['gallerynid'])) {
      $gallery = node_load($context['gallerynid']);
      $gallery_type = $gallery->type;
      $relationship = node_gallery_get_relationship($gallery_type);
      $image_type = $relationship['image_type'];
    }
    elseif (isset($context['image_type'])) {
      $image_type = $context['image_type'];
      $gallery_type = $i2g[$context['image_type']];
      $gallery = (object) array(
        'type' => $gallery_type,
      );
    }
  }
  if (!isset($user_gids[$user->uid])) {
    $user_gids[$user->uid] = node_gallery_get_gallery_list($gallery_type, $user->uid);
  }
  $gallery_list = array();
  if ($context['allow_new_gallery'] == TRUE) {
    if (isset($context['image_type'])) {
      $gallery_type = $i2g[$context['image_type']];
      if (node_gallery_user_access('create', $gallery)) {
        $gallery_list['new_gallery'] = '<' . t('Create a new gallery') . '>';
      }
    }
  }

  // @todo: there's an odd bug here where an anonymous user with privs to view "Manage Images" can see all galleries in the dropdown.
  $gallery_list += $user_gids[$user->uid];
  $form['gid'] = array(
    '#type' => 'select',
    '#title' => t('Assign to Gallery'),
    '#options' => $gallery_list,
    '#weight' => -2,
  );
  if (isset($context['gallerynid'])) {
    $form['gid']['#default_value'] = $context['gallerynid'];
  }
  return $form;
}