function simple_node_importer_form_alter in Simple Node Importer 7
Same name and namespace in other branches
- 8 simple_node_importer.module \simple_node_importer_form_alter()
Implements hook_form_alter().
File
- ./
simple_node_importer.module, line 196 - Render Simple node importing.
Code
function simple_node_importer_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'simple_node_node_form') {
// Set the session variable to false.
$_SESSION['file_upload_session'] = FALSE;
$content_type_selected = array();
$content_type_select = variable_get('content_type_select');
$content_type_selected['_none'] = t("- Select a value -");
if (!empty($content_type_select)) {
foreach ($content_type_select as $key => $value) {
if ($value) {
$content_type_selected[$key] = str_replace("_", " ", ucwords($value));
}
}
}
if (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == 'edit') {
drupal_set_message(t('OOPs! Sorry you are not allowed to resubmit this node again. Please start with new import.'));
$nid = arg(1);
$node = node_load($nid);
$form['field_content_type'][LANGUAGE_NONE]['#default_value'] = $node->field_content_type[LANGUAGE_NONE][0]['value'];
$form['field_content_type']['#disabled'] = TRUE;
$form['actions']['submit']['#disabled'] = TRUE;
$form['actions']['preview']['#disabled'] = TRUE;
}
$form['title']['#required'] = FALSE;
$form['title']['#access'] = FALSE;
$form['field_content_type'][LANGUAGE_NONE]['#options'] = $content_type_selected;
$form['field_content_type']['#weight'] = -25;
$form['field_content_type'][LANGUAGE_NONE]['#ajax'] = array(
'callback' => 'simple_node_importer_ajax_breif_note_callback',
'wrapper' => 'replace_breif_note_div',
);
$form['content_info'] = array(
'#markup' => '',
'#prefix' => '<div id="replace_breif_note_div">',
'#suffix' => '</div>',
'#weight' => -20,
);
$form['download_template'] = array(
'#type' => 'submit',
'#value' => t('Download Sample File'),
'#weight' => -15,
'#submit' => array(
'simple_node_importer_template_submit_handler',
),
'#limit_validation_errors' => array(
array(
'field_content_type',
),
),
'#states' => array(
'invisible' => array(
':input[name="field_content_type[und]"]' => array(
'value' => '_none',
),
),
),
);
// If variable 'content_type_select' is empty, redirect to
// configure the simple node import module settings page.
if (empty($content_type_select)) {
$form['field_content_type']['#access'] = FALSE;
$form['field_upload_csv']['#access'] = FALSE;
$form['download_template']['#access'] = FALSE;
$message = t('Kindly contact Admin to select the content types which are allowed to be imported, for this you can visit') . l(t('Config Simple Node Import'), 'admin/config/development/snodeimport');
drupal_set_message($message);
}
$form['field_upload_csv'][LANGUAGE_NONE][0]['#upload_validators']['simple_node_importer_field_upload_csv_validator'] = array(
$form_id,
$form_state,
);
$form['actions']['submit']['#submit'][] = "simple_node_importer_form_submit_redirect_handler";
}
if ($form_id == 'simple_node_importer_config_form') {
$form['#submit'][] = 'simple_node_importer_config_form_submit';
}
}