function gallery_assist_edit_one in Gallery Assist 6
Allow to edit each Gallery Assist Item separately.
1 string reference to 'gallery_assist_edit_one'
- gallery_assist_menu in ./
gallery_assist.module - Implementation of hook_menu().
File
- ./
gallery_assist.module, line 1777 - Drupal content type with gallery functionality.
Code
function gallery_assist_edit_one($form_state, $node, $pid) {
// Check if the image exists.
if (!isset($node->gallitems[$pid])) {
drupal_set_message(t('The requested image not exist or is not longer published.'));
drupal_goto('node/' . $node->nid);
}
global $user;
$data = variable_get('gallery_assist_' . $node->type . '_data', FALSE);
if (gallery_assist_check_access($node, 'edit')) {
$conf = $node->gallconf[$node->type];
$form = array();
$breadcrumb = drupal_get_breadcrumb();
$breadcrumb[1] = l($node->title, 'node/' . $node->nid);
$breadcrumb[2] = l($node->gallitems[$pid]->ptitle, 'node/' . $node->nid . '/' . $pid);
drupal_set_breadcrumb($breadcrumb);
drupal_set_title(check_plain($node->title));
if ($conf['show_backlink'] == 1) {
$backlink = l('« ' . t('Back to @ptitle', array(
'@ptitle' => $node->gallitems[$pid]->ptitle,
)), 'node/' . $node->nid . '/' . $pid);
}
$types = node_get_types();
foreach ($types as $type) {
//if (!empty($pid) && array_key_exists($pid, $node->gallitems) && $user->uid == 1 || $user->uid == $node->uid) {
if (!empty($pid) && array_key_exists($pid, $node->gallitems) && gallery_assist_check_access($node, 'edit')) {
$node->pid = $pid;
$node_light = new stdClass();
$links = gallery_assist_item_pager($node, 'edit-one');
$extras['pager_position'] = $conf['pager_position'];
$pager = count($node->gallitems) > 1 ? theme('gallery_assist_pager', $node_light, $links['all'], $extras) : '';
$form['gallery_assist_edit_one'] = array(
'#type' => 'fieldset',
'#title' => t('Edit one item'),
'#prefix' => '<div id="edit-and-save-one-wrapper"></div>',
);
$form['gallery_assist_edit_one']['backlink'] = array(
'#type' => 'markup',
'#value' => $backlink,
);
$form['gallery_assist_edit_one']['pager'] = array(
'#type' => 'markup',
'#value' => $pager,
);
$form['gallery_assist_edit_one']['ptitle'] = array(
'#type' => 'textfield',
'#title' => t('Title'),
'#default_value' => $node->gallitems[$pid]->ptitle,
);
$form['gallery_assist_edit_one']['palt'] = array(
'#type' => 'textfield',
'#title' => t('Image alternative text'),
'#default_value' => $node->gallitems[$pid]->palt,
);
$form['gallery_assist_edit_one']['copyright'] = array(
'#type' => 'textfield',
'#title' => t('Copyright'),
'#default_value' => $node->gallitems[$pid]->copyright,
);
$item = new \stdClass();
if (function_exists('imagecache_preset') && $node->gallconf[$node->type]['use_imagecache'] == 1) {
$item->image = theme('imagecache', $node->gallconf[$node->type]['thm_presetname'], $node->gallitems[$pid]->opath, $node->gallitems[$pid]->palt, $node->gallitems[$pid]->ptitle);
}
else {
$item->image = theme('image', file_create_url($node->gallitems[$pid]->tpath), $node->gallitems[$pid]->palt, $node->gallitems[$pid]->ptitle, NULL, FALSE);
}
$item->image_link = l($item->image, 'node/' . $node->nid . '/' . $pid, array(
'html' => TRUE,
));
$form['gallery_assist_edit_one']['pictitle'] = array(
'#type' => 'item',
'#value' => $item->image_link,
);
$form['gallery_assist_edit_one']['pdescription'] = array(
'#type' => 'textarea',
'#title' => t('Caption'),
'#default_value' => $node->gallitems[$pid]->pdescription,
'#rows' => 5,
);
if (!isset($node->gallitems[$pid]->format)) {
$pdescription['format'] = FILTER_FORMAT_DEFAULT;
}
else {
$pdescription['format'] = $node->gallitems[$pid]->format;
}
$form['gallery_assist_edit_one']['format'] = filter_form($pdescription['format']);
$form['gallery_assist_edit_one']['weight'] = array(
'#type' => 'textfield',
'#title' => t('Weight'),
'#default_value' => $node->gallitems[$pid]->weight,
'#size' => 5,
);
$form['gallery_assist_edit_one']['sid'] = array(
'#type' => 'checkbox',
'#title' => t('Allow Download'),
'#default_value' => $node->gallitems[$pid]->sid,
'#disabled' => empty($data['show_download_link']) ? TRUE : FALSE,
'#access' => $data['show_download_link'] ? TRUE : FALSE,
'#size' => 5,
);
$form['gallery_assist_edit_one']['cover'] = array(
'#type' => 'checkbox',
'#title' => t('Gallery-Cover'),
'#description' => t('Set this image to the gallery cover.'),
'#default_value' => $node->gallitems[$pid]->cover,
'#disabled' => $node->gallitems[$pid]->cover,
'#access' => $node->gallitems[$pid]->cover ? FALSE : TRUE,
);
$form['gallery_assist_edit_one']['language'] = array(
'#type' => 'hidden',
'#value' => $node->language,
);
$form['gallery_assist_edit_one']['aid'] = array(
'#type' => 'hidden',
'#value' => $node->gallitems[$pid]->aid,
);
$form['gallery_assist_edit_one']['nid'] = array(
'#type' => 'hidden',
'#value' => $node->nid,
);
$form['gallery_assist_edit_one']['ref'] = array(
'#type' => 'hidden',
'#value' => $node->ref,
);
$form['gallery_assist_edit_one']['pid'] = array(
'#type' => 'hidden',
'#value' => $pid,
);
$form['gallery_assist_edit_one']['fid'] = array(
'#type' => 'hidden',
'#value' => $node->gallitems[$pid]->fid,
);
$form['gallery_assist_edit_one']['node_type'] = array(
'#type' => 'hidden',
'#value' => $node->type,
);
$form['gallery_assist_edit_one']['editone'] = array(
'#type' => 'submit',
'#value' => t('Save and edit'),
'#name' => 'editone',
'#ahah' => array(
'path' => $node->type == 'gallery_assist' ? 'gallery_assist_save_one_js/js/' . $pid : 'gallery_assist_save_one_' . $node->type . '_js/js/' . $pid,
'wrapper' => 'edit-and-save-one-wrapper',
'progress' => array(
'type' => 'bar',
'message' => t('Please wait...'),
),
),
);
$form['gallery_assist_edit_one']['editone2'] = array(
'#type' => 'submit',
'#value' => t('Save'),
'#name' => 'editone2',
'#submit' => array(
'gallery_assist_save_one_submit',
),
);
$form['gallery_assist_edit_one']['deleteone'] = array(
'#type' => 'submit',
'#value' => t('Delete'),
'#name' => 'deleteone',
'#submit' => array(
'gallery_assist_delete_one_submit',
),
'#redirect' => url("node/{$node->nid}"),
);
// Build the query string to complete the link and so make exact the redirect.
$myPath = array();
$myPath[] = 'node/' . $node->nid;
if ($_GET['page']) {
$myPath[] = 'page=' . $_GET['page'];
}
if ($_GET['titles']) {
$myPath[] = 'titles=' . $_GET['titles'];
}
$form['#redirect'] = $myPath;
}
}
return $form;
}
else {
drupal_access_denied();
}
}