theme_scaffolding_example_overview_form
- Versions
- 7
theme_scaffolding_example_overview_form($form)
Theme the drag-and-drop overview form.
Arranges records in a table, and adds the css and js for draggable sorting.
See also
scaffolding_example_overview_form()
Related topics
Code
developer/examples/scaffolding_example/scaffolding_example.admin.inc, line 127
<?php
function theme_scaffolding_example_overview_form($form) {
// Each record has a 'weight' that can be used to arrange it in relation to
// other records. Drupal's tabledrag.js library allows users to control these
// weights by dragging and dropping the records in a list -- we just need to
// add identifying CSS classes to key elements in the table.
$rows = array();
foreach (element_children($form['records']) as $key) {
$row = array();
// Render the hidden 'record id' field and the title of the record into the
// same column of the row.
$row[] = drupal_render($form['records'][$key]['record_id']) . drupal_render($form['records'][$key]['title']);
// Add an identifying CSS class to our weight field, as it's the one
// the tabledrag.js will be controlling. This can be anything we want it to
// be, we'll just tell the tabledrag.js library what it should look for.
$form['records'][$key]['weight']['#attributes']['class'] = 'scaffolding-example-weight';
$row[] = drupal_render($form['records'][$key]['weight']);
// Render the edit and delete links into their own column.
$row[] = drupal_render($form['records'][$key]['operations']);
// Add the new row to our collection of rows, and give it the 'draggable'
// class, indicating that it should be... well, draggable.
$rows[] = array(
'data' => $row,
'class' => 'draggable',
);
}
// If there were no records found, note the fact so users don't get confused
// by a completely empty table.
if (count($rows) == 0) {
$rows[] = array(t('No records have been added.'), '<span class="scaffolding-example-weight"></span>', '');
}
// Render a list of header titles, and our array of rows, into a table. Even
// we've already rendered all of our records, we always call drupal_render()
// on the form itself after we're done, so hidden security fields and other
// elements (like buttons) will appear properly at the bottom of the form.
$header = array(t('Title'), t('Weight'), t('Operations'));
$output = theme('table', $header, $rows, array('id' => 'scaffolding-example-overview'));
$output .= drupal_render($form);
// Now that we've built our output, tell Drupal to add the tabledrag.js library.
// We'll pass in the ID of the table, the behavior we want it to use, and the
// class that appears on each 'weight' form element it should be controlling.
drupal_add_tabledrag('scaffolding-example-overview', 'order', 'self', 'scaffolding-example-weight');
return $output;
}
?>Login or register to post comments 