function _book_helper_admin_table_tree in Book helper 7
Same name and namespace in other branches
- 6 book_helper.admin.inc \_book_helper_admin_table_tree()
Recursive helper to build the main table in the book administration page form.
See also
1 call to _book_helper_admin_table_tree()
- _book_helper_admin_table in ./
book_helper.admin.inc - Build the table portion of the form for the book administration page.
File
- ./
book_helper.admin.inc, line 279 - Administration page for the 'Book helper' module.
Code
function _book_helper_admin_table_tree($tree, &$form, $bid) {
// Create a cache of all the book's node titles.
static $node_titles;
if (!isset($node_titles)) {
$node_titles = array();
$result = db_query('SELECT n.nid, n.title FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE bid = :bid', array(
':bid' => $bid,
));
foreach ($result as $record) {
if (function_exists('node_parent_title_remove')) {
$record['title'] = node_parent_title_remove($record->title);
}
$node_titles[$record->nid] = $record->title;
}
}
// The delta must be big enough to give each node a distinct value.
$count = count($tree);
$delta = $count < 30 ? 15 : intval($count / 2) + 1;
foreach ($tree as $data) {
$node_title = $node_titles[$data['link']['nid']];
$form['book-admin-' . $data['link']['nid']] = array(
'#item' => $data['link'],
'nid' => array(
'#type' => 'value',
'#value' => $data['link']['nid'],
),
'depth' => array(
'#type' => 'value',
'#value' => $data['link']['depth'],
),
'href' => array(
'#type' => 'value',
'#value' => $data['link']['href'],
),
'link_title' => array(
'#type' => 'textfield',
'#default_value' => $data['link']['link_title'],
'#maxlength' => 255,
'#size' => 15,
),
// New code: Allows node title to be customized.
'title' => array(
'#type' => 'textfield',
'#default_value' => $node_title,
'#maxlength' => 255,
'#size' => 15,
),
'link_title_sync' => array(
'#type' => 'checkbox',
'#default_value' => $node_title == $data['link']['link_title'] ? TRUE : FALSE,
),
'weight' => array(
'#type' => 'weight',
'#default_value' => $data['link']['weight'],
'#delta' => max($delta, abs($data['link']['weight'])),
'#title' => t('Weight for @title', array(
'@title' => $data['link']['title'],
)),
'#title_display' => 'invisible',
),
'plid' => array(
'#type' => 'hidden',
'#default_value' => $data['link']['plid'],
),
'mlid' => array(
'#type' => 'hidden',
'#default_value' => $data['link']['mlid'],
),
// New code: Add checkbox element for hidden.
'hidden' => array(
'#type' => 'checkbox',
// Hidden is a special case, the value needs to be reversed.
'#default_value' => !$data['link']['hidden'],
),
);
if ($data['below']) {
_book_helper_admin_table_tree($data['below'], $form, $bid);
}
}
return $form;
}