function theme_scs_sortable_table in Simplenews Content Selection 8
Same name and namespace in other branches
- 7.2 scs.theme.inc \theme_scs_sortable_table()
- 7 scs.theme.inc \theme_scs_sortable_table()
Theme the node selection form.
File
- ./
scs.theme.inc, line 13 - Theming preprocesses
Code
function theme_scs_sortable_table($form) {
$form = $form['form'];
$headers = array(
t('Node title'),
t('Weight'),
t('View mode'),
);
$rows = array();
$nids = element_children($form['nodes']);
// Fetch the titles for each nid
$titles = \Drupal::database()
->select('node', 'n')
->fields('n', array(
'nid',
'title',
))
->condition('nid', array_values($nids))
->execute()
->fetchAllKeyed();
foreach ($nids as $nid) {
$row = array();
$row[] = $titles[$nid];
$row[] = \Drupal::service('renderer')
->render($form['nodes'][$nid]['weight']);
$row[] = \Drupal::service('renderer')
->render($form['nodes'][$nid]['view_mode']);
$rows[] = array(
'data' => $row,
'class' => array(
'draggable',
),
);
}
$output = theme('table', array(
'header' => $headers,
'rows' => $rows,
'attributes' => array(
'id' => 'scs-sort-nodes',
),
));
$info = '';
if (isset($form['scs_title']) && isset($form['scs_toc'])) {
$info = \Drupal::service('renderer')
->render($form['scs_title']) . \Drupal::service('renderer')
->render($form['scs_toc']);
}
$result = '';
foreach (Element::children($form) as $key) {
if (!empty($form[$key])) {
$result .= \Drupal::service('renderer')
->render($form[$key]);
}
}
$output = $info . $output . $result;
drupal_add_tabledrag('scs-sort-nodes', 'order', 'sibling', 'node-weight');
return $output;
}