function menu_import_form_step1 in Menu Export/Import 7
Step 1 of menu import process.
File
- includes/
admin.inc, line 32 - Administrative page callbacks for menu_import module.
Code
function menu_import_form_step1(&$form, &$form_state) {
$form['menu_name'] = array(
'#type' => 'select',
'#title' => t('Target menu'),
'#options' => menu_get_menus(),
'#description' => t('This menu will contain the imported items.'),
'#required' => TRUE,
'#default_value' => !empty($form_state['values']['menu_name']) ? $form_state['values']['menu_name'] : NULL,
);
$form['import_source'] = array(
'#type' => 'fieldset',
'#title' => t('Source'),
'#description' => t('The source file/text must contain menu definition. See !help for format details.', array(
'!help' => l(t('help'), 'admin/help/menu_import'),
)),
);
$form['import_source']['upload'] = array(
'#type' => 'file',
'#title' => t('Menu file'),
);
$form['import_source']['text_import'] = array(
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#title' => t('Text import'),
'#description' => t('Type/paste menu definition here'),
);
$form['import_source']['text_import']['text'] = array(
'#type' => 'textarea',
'#default_value' => !empty($form_state['values']['text']) ? $form_state['values']['text'] : '',
);
$form['options'] = array(
'#type' => 'fieldset',
'#title' => t('Options'),
);
$form['options']['link_to_content'] = array(
'#type' => 'checkbox',
'#title' => t('Link to existing content'),
'#description' => t('Look for existing content by path or title.'),
'#default_value' => !empty($form_state['values']['link_to_content']) ? $form_state['values']['link_to_content'] : 1,
);
$form['options']['remove_menu_items'] = array(
'#type' => 'checkbox',
'#title' => t('Remove existing menu items'),
'#description' => t('Remove current menu items before running import.'),
'#default_value' => !empty($form_state['values']['remove_menu_items']) ? $form_state['values']['remove_menu_items'] : 0,
);
$form['options']['create_content'] = array(
'#type' => 'checkbox',
'#title' => t('Create initial content'),
'#description' => t('Create initial content if none was found.'),
'#default_value' => !empty($form_state['values']['create_content']) ? $form_state['values']['create_content'] : 0,
);
$langs = language_list();
// We do not use lambda function here for the sake of 5.2.x support.
function language_list_get_names($item) {
return $item->name;
}
$lang_opts = array_map('language_list_get_names', $langs);
$form['options']['language'] = array(
'#type' => 'select',
'#title' => t('Default language'),
'#description' => t('Here you can set the default language of newly created content and/or menu items.' . ' If menu item has its own valid language it will override the default one.'),
'#empty_option' => t('- Not defined -'),
'#empty_value' => LANGUAGE_NONE,
'#options' => $lang_opts,
'#required' => FALSE,
);
$form['node'] = array(
'#type' => 'fieldset',
'#title' => t('Content settings'),
'#attributes' => empty($form_state['values']['create_content']) && empty($form_state['input']['create_content']) ? array(
'style' => 'display: none',
) : NULL,
);
$node_types = node_type_get_names();
// Disable content generation if no content types were found.
if (empty($node_types)) {
$form['main']['create_content']['#disabled'] = TRUE;
}
$form['node']['node_type'] = array(
'#type' => 'select',
'#title' => t('Content type'),
'#options' => $node_types,
'#description' => t('Type of the newly created content.'),
'#default_value' => !empty($form_state['values']['node_type']) ? $form_state['values']['node_type'] : NULL,
);
// Provide lorem ipsum as default body value.
$default_body_value = 'Lorem ipsum dolor sit amet, quis aenean at euismod venenatis ' . 'interdum ante, placerat nunc metus, velit adipiscing purus mauris, aliquet ' . 'eros molestie mauris morbi odio egestas, porttitor amet. Suspendisse ' . 'vestibulum maiores non, nonummy mauris velit, habitasse montes quam eros. ' . 'Et condimentum lorem adipiscing dolor, in sed libero, tellus purus magnis, ' . 'nec non bibendum. Erat magnis ut, mauris suspendisse vestibulum dictum tincidunt.';
$form['node']['node_body'] = array(
'#type' => 'textarea',
'#title' => t('Body'),
'#description' => t('The initial content of the "Body" field. "Filtered HTML" filter will be used.'),
'#default_value' => !empty($form_state['values']['node_body']) ? $form_state['values']['node_body'] : $default_body_value,
);
$formats = filter_formats();
function filter_formats_get_names($item) {
return $item->name;
}
$filter_opts = array_map('filter_formats_get_names', $formats);
$form['node']['node_format'] = array(
'#type' => 'select',
'#options' => $filter_opts,
'#title' => t('Body format'),
'#default_value' => !empty($form_state['values']['node_format']) ? $form_state['values']['node_format'] : 'filtered_html',
);
$users = db_query('SELECT uid, name FROM {users} WHERE uid <> 0')
->fetchAllKeyed();
$form['node']['node_author'] = array(
'#type' => 'select',
'#title' => t('Authored by'),
'#options' => $users,
'#description' => t('Attribute authorship to the selected user.'),
'#default_value' => !empty($form_state['values']['node_author']) ? $form_state['values']['node_author'] : $GLOBALS['user']->uid,
);
$form['node']['node_status'] = array(
'#type' => 'checkbox',
'#title' => t('Published'),
'#description' => t('Check to automatically publish the created content.'),
'#default_value' => !empty($form_state['values']['node_status']) ? $form_state['values']['node_status'] : 1,
);
$form['node']['node_alias'] = array(
'#type' => 'checkbox',
'#title' => t('Create path alias'),
'#description' => t('Check to use the provided path as alias. The path has to go right after the title in your text file.'),
'#default_value' => !empty($form_state['values']['node_status']) ? $form_state['values']['node_status'] : 1,
);
drupal_add_js('(function($) {
$(function() {
$("input[name=create_content]").change(function() {
if ($(this).attr("checked")) {
$("#edit-node").fadeIn();
}
else {
$("#edit-node").fadeOut();
}
});
// Show text input area if it has any contents.
if ($("textarea[name=text]").val()) {
$("#edit-text-import a.fieldset-title").click();
};
});
})(jQuery)', 'inline');
$form['actions'] = array(
'#type' => 'actions',
);
$form['actions']['sumbit'] = array(
'#type' => 'submit',
'#value' => t('Upload & preview'),
'#submit' => array(
'menu_import_form_step1_submit',
),
'#validate' => array(
'menu_import_form_step1_validate',
),
);
}