function node_gallery_api_form_alter in Node Gallery 7
Implements hook_form_alter().
File
- ./
node_gallery_api.module, line 287 - Node Gallery module.
Code
function node_gallery_api_form_alter(&$form, $form_state, $form_id) {
if (!empty($form['#node']->node_gallery_target_id) && !empty($form['#node']->node_gallery_field_name)) {
// TODO: This is real garbage. Need to rework this.
array_unshift($form['actions']['submit']['#submit'], 'node_gallery_api_upload_submit');
$form[$form['#node']->node_gallery_field_name][LANGUAGE_NONE]['#access'] = FALSE;
$form['node_gallery_target_id'] = array(
'#type' => 'value',
'#value' => $form['#node']->node_gallery_target_id,
);
$form['node_gallery_field_name'] = array(
'#type' => 'value',
'#value' => $form['#node']->node_gallery_field_name,
);
return;
}
// If displaying our VBO image weight form, theme it.
if (strpos($form_id, 'views_bulk_operations_form') !== FALSE && isset($form['node_gallery_change_image_weight_action']) && isset($form['#ngtheme'])) {
$form['#theme'] = $form['#ngtheme'];
unset($form['#ngtheme']);
}
elseif (!empty($form['#node_edit_form'])) {
if (in_array($form['type']['#value'], (array) node_gallery_api_get_types('gallery'))) {
// Gallery node form.
$form['buttons']['submit']['#submit'][] = 'node_gallery_create_gallery_redirect_submit';
}
elseif (in_array($form['type']['#value'], (array) node_gallery_api_get_types('item'))) {
// Item node form.
$fieldname = node_gallery_api_get_item_field_name(NULL, $form['type']['#value']);
$menu_item = menu_get_item();
if ($menu_item['path'] == 'node/%/upload') {
// Pull the gallery object, and pre-fill in the gallery info.
$fieldname = node_gallery_api_get_item_field_name(NULL, $form['type']['#value']);
if (isset($form[$fieldname][LANGUAGE_NONE]['#options'])) {
$form[$fieldname][LANGUAGE_NONE] = array(
'#type' => 'value',
'#value' => array(
$menu_item['map'][1]->nid,
),
);
}
}
elseif ($menu_item['path'] == 'node/%/items') {
}
else {
// TODO: Make sure users have the ability to create new galleries.
if (isset($form[$fieldname][LANGUAGE_NONE]['#options'])) {
$option_keys = array_keys($form[$fieldname][LANGUAGE_NONE]['#options']);
if ($option_keys[0] == '_none') {
$none_option = $form[$fieldname][LANGUAGE_NONE]['#options']['_none'];
unset($form[$fieldname][LANGUAGE_NONE]['#options']['_none']);
}
$form[$fieldname][LANGUAGE_NONE]['#options'] = array(
'_node_gallery_create' => t('- Create a new gallery -'),
) + $form[$fieldname][LANGUAGE_NONE]['#options'];
if ($none_option) {
$form[$fieldname][LANGUAGE_NONE]['#options'] = array(
'_none' => $none_option,
) + $form[$fieldname][LANGUAGE_NONE]['#options'];
}
if (empty($form[$fieldname][LANGUAGE_NONE]['#default_value'])) {
$form[$fieldname][LANGUAGE_NONE]['#default_value'] = '_node_gallery_create';
}
array_unshift($form['actions']['submit']['#submit'], 'node_gallery_api_create_new_gallery_submit');
$form['actions']['submit']['#submit'][] = 'node_gallery_api_gallery_edit_redirect';
}
}
}
}
}