function om_maximenu_import in OM Maximenu 7
Same name and namespace in other branches
- 8 inc/om_maximenu.import.inc \om_maximenu_import()
- 6 inc/om_maximenu.import.inc \om_maximenu_import()
Import from existing menus
1 string reference to 'om_maximenu_import'
- om_maximenu_menu in ./
om_maximenu.module - Implementation of hook_menu().
File
- inc/
om_maximenu.import.inc, line 16 - OM Maximenu Import
Code
function om_maximenu_import() {
global $_om_maximenu_variable;
global $_om_maximenu_existing_menus;
global $_om_maximenu_existing_terms;
drupal_set_title(t('OM Maximenu Import'));
$maximenu = $_om_maximenu_variable;
//dsm($maximenu);
$form = array();
$form['om_import'] = array(
'#type' => 'fieldset',
'#collapsible' => FALSE,
'#collapsed' => FALSE,
'#tree' => TRUE,
);
// menus
$form['om_import']['menus'] = array(
'#type' => 'fieldset',
'#title' => t('Menus'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#description' => t('Menu tree will not be preserved on import. Any menu or link with submenus will be flattened.'),
);
// getting existing menu
$result_menus = db_query("SELECT menu_name, mlid, plid, link_title FROM {menu_links} WHERE hidden = 0 AND TRIM(link_title) > '' ORDER BY menu_name ASC");
$excluded_menus = array();
while ($record_menus = $result_menus
->fetchObject()) {
if (!in_array($record_menus->menu_name, $excluded_menus)) {
$_om_maximenu_existing_menus[$record_menus->menu_name][$record_menus->plid][$record_menus->mlid] = $record_menus->link_title;
}
}
foreach ($_om_maximenu_existing_menus as $menu_name => $tree) {
$options = array();
om_menu_tree_options($options, $tree[0], $menu_name);
$menu_title = ucwords(preg_replace('/-/', ' ', $menu_name));
$none = array(
'' => '<none>',
$menu_name => $menu_title,
);
$options = $none + $options;
$form['om_import']['menus'][$menu_name]['mlid'] = array(
'#type' => 'select',
'#title' => t($menu_title),
'#options' => $options,
'#default_value' => '',
);
$form['om_import']['menus'][$menu_name]['menu_list'] = array(
'#type' => 'hidden',
'#value' => implode(',', array_keys($options)),
);
}
if (module_exists('taxonomy')) {
// vocabularies
$form['om_import']['vocabularies'] = array(
'#type' => 'fieldset',
'#title' => t('Vocabularies'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#description' => t('Create menus from your existing vocabularies.'),
);
// getting existing vocabularies
$result_terms = db_query("SELECT t.tid AS term_id, t.vid, t.name, t.description, t.weight, v.vid AS voc_id, v.name AS vocabulary \n FROM {taxonomy_term_data} t JOIN {taxonomy_vocabulary} v ON t.vid = v.vid");
while ($record_terms = $result_terms
->fetchObject()) {
$vocabularies[$record_terms->voc_id] = $record_terms->vocabulary;
$_om_maximenu_existing_terms[$record_terms->voc_id][$record_terms->term_id]['term_id'] = $record_terms->term_id;
$_om_maximenu_existing_terms[$record_terms->voc_id][$record_terms->term_id]['term'] = $record_terms->name;
$_om_maximenu_existing_terms[$record_terms->voc_id][$record_terms->term_id]['description'] = $record_terms->description;
$_om_maximenu_existing_terms[$record_terms->voc_id][$record_terms->term_id]['weight'] = $record_terms->weight;
}
if (isset($vocabularies) && !empty($vocabularies)) {
foreach ($vocabularies as $voc_id => $vocabulary) {
$form['om_import']['vocabularies'][$voc_id]['enabled'] = array(
'#type' => 'checkbox',
'#title' => $vocabulary,
'#default_value' => '',
);
$form['om_import']['vocabularies'][$voc_id]['voc_list'] = array(
'#type' => 'hidden',
'#value' => $vocabularies,
);
}
}
}
$form['save'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}