public function PowerMenuTaxonomyHandler::menuFormAlter in Power Menu 7.2
Overrides PowerMenuHandlerInterface::menuFormAlter
See also
PowerMenuHandlerInterface::menuFormAlter()
File
- plugins/
menu_handlers/ PowerMenuTaxonomyHandler.class.php, line 123
Class
- PowerMenuTaxonomyHandler
- Implementation of the interface PowerMenuHandlerInterface.
Code
public function menuFormAlter(&$menu_item_form, &$form_state) {
$form = array();
$vocabulary = variable_get('power_menu_taxonomy_vocabulary', array(
'vid' => NULL,
'machine_name' => NULL,
));
if ($vocabulary['vid'] !== NULL) {
$vocabulary = taxonomy_vocabulary_load($vocabulary['vid']);
$vocabulary_name = $vocabulary->name;
$terms = taxonomy_get_tree($vocabulary->vid);
$mlid = arg(4);
$used_terms = variable_get('power_menu_taxonomy_terms', array());
// Get only the used terms for this mlid
foreach ($used_terms as $key => $value) {
if ($mlid != $value) {
unset($used_terms[$key]);
}
}
// Only the key is needed for #default_value
$used_terms = array_keys($used_terms);
// Create the hierarchy and make sure that we mark the ones that are not selectable, because they already belong to an other menu item
if ($terms) {
foreach ($terms as $term) {
$choice = new stdClass();
$choice->option = array(
$term->tid => str_repeat('-', $term->depth) . ' ' . $term->name,
);
$options[] = $choice;
}
}
$form['power_menu_taxonomy_create'] = array(
'#type' => 'checkbox',
'#title' => t('Create Taxonomy term'),
'#default_value' => $menu_item_form['mlid']['#value'] == 0 && variable_get('power_menu_taxonomy_default_enable_create_term', TRUE) ? TRUE : FALSE,
'#description' => t('The name of the taxonomy term is going to be the title of the menu link. When it\'s possible, the same hierarchy as the menu-item is used.', array(
'%vocabulary' => $vocabulary_name,
)),
);
$form['power_menu_taxonomy_terms'] = array(
'#type' => 'select',
'#title' => t('Link to existing term'),
'#multiple' => TRUE,
'#options' => $options,
'#default_value' => $used_terms,
'#description' => t('Choose a taxonomy term. When displaying a node that has the selected taxonomy term, this menu item will set to active. A term can only belong to one menu item and is a term not selectable it is already asigned to other menu items.'),
'#post_render' => array(
'power_menu_taxonomy_terms_post_render',
),
);
}
else {
$form['power_menu_taxonomy'] = array(
'#markup' => t('No menu vocabulary selected. !config_page', array(
'!config_page' => l(t('Go to the plugin configuration page.'), 'admin/config/search/power_menu/handler/edit/taxonomy'),
)),
);
}
return $form;
}