function biblio_import_form in Bibliography Module 7
Same name and namespace in other branches
- 6.2 includes/biblio.import.export.inc \biblio_import_form()
- 6 biblio.import.export.inc \biblio_import_form()
- 7.2 includes/biblio.import.export.inc \biblio_import_form()
Return a form used to import files into biblio.
Return value
An array which will be used by the form builder to build the import form
2 string references to 'biblio_import_form'
- biblio_import_form_validate in includes/
biblio.import.export.inc - Implementation of hook_validate() for the biblio_import_form.
- biblio_menu in ./
biblio.module - Implements hook_menu().
File
- includes/
biblio.import.export.inc, line 61 - Functions that are used to import and export biblio data.
Code
function biblio_import_form($form, &$form_state) {
global $user;
$msg = '';
$biblio_vocabs = array();
// && !user_access('administer nodes')) {.
if (biblio_access('import')) {
$form['#attributes']['enctype'] = 'multipart/form-data';
$form['biblio_import_file'] = array(
'#type' => 'file',
'#title' => t('Import file'),
'#default_value' => '',
'#size' => 60,
);
$import_options = module_invoke_all('biblio_import_options');
if (count($import_options) > 1) {
$form['filetype'] = array(
'#type' => 'select',
'#title' => t('File Type'),
'#default_value' => 0,
'#options' => array(
'0' => t('Select type'),
),
);
$form['filetype']['#options'] = array_merge($form['filetype']['#options'], $import_options);
asort($form['filetype']['#options']);
}
elseif (count($import_options) == 1) {
$form['biblio_import_file']['#description'] = t('Import type: @option', array(
'@option' => current($import_options),
));
$form['filetype'] = array(
'#type' => 'value',
'#value' => key($import_options),
);
}
elseif (count($import_options) == 0) {
$form['biblio_import_file']['#disabled'] = TRUE;
drupal_set_message(t("You won't be able to select a file until you enable at least one import module."), 'error');
}
$form['batch_process'] = array(
'#type' => 'checkbox',
'#title' => t('Batch Process'),
'#default_value' => 1,
'#description' => t('You should use batch processing if your import file contains more than about 20 records, or if you are experiencing script timeouts during import'),
);
$form['userid'] = _biblio_admin_build_user_select($user->uid);
// Get the vocabularies attached to the biblio node type ...
foreach (field_info_instances('node', 'biblio') as $instance) {
$field = field_info_field_by_id($instance['field_id']);
if ($field['type'] == 'taxonomy_term_reference') {
foreach ($field['settings']['allowed_values'] as $delta => $tree) {
$biblio_vocabs[$tree['vocabulary']] = array(
'instance' => $instance,
'field' => $field,
);
}
}
}
// ... and print a form to select the terms in each of them.
$form['import_taxonomy'] = array(
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#title' => t('Taxonomy Settings'),
'#description' => t('Typically you don\'t have to do anything here, however if you wish, you may select terms to be assigned to imported records. This effectively adds a keyword to all entries being imported.'),
);
if (count($biblio_vocabs)) {
$vocabularies = module_invoke('taxonomy', 'get_vocabularies', 'biblio');
if (variable_get('biblio_keyword_freetagging', 0)) {
$freetag_vocab = $vocabularies[variable_get('biblio_keyword_vocabulary', 0)];
unset($vocabularies[variable_get('biblio_keyword_vocabulary', 0)]);
$msg = t('<b>NOTE:</b> Keyword "free tagging" is turned on, consequently all incomming keywords will be added to the <b>@name</b> vocabulary as specified in the "Keyword" section of the !url page.', array(
'@name' => $freetag_vocab->name,
'!url' => l(t('admin/config/content/biblio'), 'admin/config/content/biblio'),
));
}
else {
$msg = t('<b>NOTE:</b> Keyword "free tagging" is turned off, consequently keywords will <b>NOT</b> be added to the vocabulary as specified in the Taxonomy section of the !url page.', array(
'!url' => l(t('admin/config/content/biblio'), 'admin/config/content/biblio'),
));
}
$i = 0;
$form += array(
'#parents' => array(),
);
$form['import_taxonomy']['vocabularies'] = array();
$term_refs = array();
foreach ($vocabularies as $vocabulary) {
if (in_array($vocabulary->machine_name, array_keys($biblio_vocabs))) {
$term_refs[] = $biblio_vocabs[$vocabulary->machine_name]['instance']['field_name'];
$entity = new stdClass();
$entity->type = 'biblio';
$field = $biblio_vocabs[$vocabulary->machine_name]['field'];
$instance = $biblio_vocabs[$vocabulary->machine_name]['instance'];
$items = array();
$form['import_taxonomy']['vocabularies'] += field_default_form('node', $entity, $field, $instance, 'und', $items, $form, $form_state);
}
}
if (!empty($term_refs)) {
$form['term_refs'] = array(
'#type' => 'hidden',
'#value' => $term_refs,
);
$form['import_taxonomy']['copy_to_biblio'] = array(
'#type' => 'checkbox',
'#title' => t('Copy these terms to the biblio keyword database'),
'#return_value' => 1,
'#default_value' => variable_get('biblio_copy_taxo_terms_to_keywords', 0),
'#description' => t('If this option is selected, the selected taxonomy terms will be copied to the ' . check_plain(variable_get('biblio_base_title', 'Biblio')) . ' keyword database and be displayed as keywords (as well as taxonomy terms) for this entry.'),
);
}
}
else {
if (module_exists('taxonomy')) {
$vocab_msg = t('There are currently no "Term references" attached to the biblio node type. If you would like to associate a Taxonomy vocabulary with the Biblio node type, go the the !url page and add one or more "Term reference" fields.', array(
'!url' => l(t('admin/structure/types/manage/biblio/fields'), 'admin/structure/types/manage/biblio/fields'),
));
}
else {
$vocab_msg = '<div class="admin-dependencies">' . t('Depends on') . ': ' . t('Taxonomy') . ' (<span class="admin-disabled">' . t('disabled') . '</span>)</div>';
}
$form['import_taxonomy']['vocabulary_message'] = array(
'#markup' => '<p><div>' . $vocab_msg . '</div></p>',
);
}
$form['import_taxonomy']['freetagging_information'] = array(
'#markup' => '<p><div>' . $msg . '</div></p>',
);
$form['button'] = array(
'#type' => 'submit',
'#value' => t('Import'),
);
return $form;
}
else {
drupal_set_message(t("You are not authorized to access the biblio import page"), 'error');
}
}