Last active
December 14, 2015 23:19
-
-
Save joelpittet/5164471 to your computer and use it in GitHub Desktop.
Menu Overview type table conversion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$form['links'] = array( | |
'#type' => 'table', | |
'#attributes' => array('id' => 'menu-overview'), | |
'#header' => array( | |
t('Menu link'), | |
array('data' => t('Enabled'), 'class' => array('checkbox')), | |
t('Weight'), | |
t('Operations'), | |
), | |
'#empty' => t('There are no menu links yet. <a href="@link">Add link</a>.', array('@link' => url('admin/structure/menu/manage/' . $form_state['menu']->id() .'/add'))), | |
'#tabledrag' => array( | |
array('match', 'parent', 'menu-plid', 'menu-plid', 'menu-mlid', TRUE, MENU_MAX_DEPTH - 1), | |
array('order', 'sibling', 'menu-weight'), | |
), | |
); | |
$links = _menu_overview_tree_form($tree, $delta); | |
foreach (element_children($links) as $mlid) { | |
$element = $links[$mlid]; | |
// Add special classes to be used for tabledrag.js. | |
$element['plid']['#attributes']['class'] = array('menu-plid'); | |
$element['mlid']['#attributes']['class'] = array('menu-mlid'); | |
$element['weight']['#attributes']['class'] = array('menu-weight'); | |
$form['links'][$mlid]['#attributes']['class'][] = 'draggable'; | |
$form['links'][$mlid]['#weight'] = $element['#item']->get('weight'); | |
$form['links'][$mlid]['title'] = array( | |
array( | |
'#theme' => 'indentation', | |
'#size' => ($element['#item']->depth - 1), | |
), | |
$element['title'], | |
); | |
$form['links'][$mlid]['hidden'] = array( | |
'data' => $element['hidden'], | |
'#attributes' => array('class' => array('checkbox', 'menu-enabled')), | |
); | |
dpm($element); | |
// HELP HERE! | |
//Clean: links[mlid:6][weight] | |
//Dirty: links[mlid:5][weight][0] | |
//Clean: links[mlid:6][plid] | |
//Dirty: links[mlid:5][weight][1] | |
//Clean: links[mlid:6][mlid] | |
//Dirty: links[mlid:5][weight][2] | |
$form['links'][$mlid]['weight'] = array( | |
$element['weight'], | |
$element['plid'], | |
$element['mlid'], | |
); | |
// Operations (dropbutton) column. | |
$form['links'][$mlid]['operations'] = $element['operations']; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment