scs.theme.inc in Simplenews Content Selection 8
Same filename and directory in other branches
Theming preprocesses
File
scs.theme.incView source
<?php
/**
* @file
* Theming preprocesses
*/
use Drupal\Core\Render\Element;
/**
* Theme the node selection form.
*/
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;
}
/**
* Preprocess for scs_newsletter.
*/
function template_preprocess_scs_newsletter(&$vars) {
// Add Table of Contents (if required)
if ($vars['toc']) {
$vars['toc'] = theme('scs_toc', array(
'nodes' => $vars['nodes'],
));
}
// Render each node using the correct view mode
foreach ($vars['nodes'] as $nid => $node) {
$build = \Drupal::entityTypeManager()
->getViewBuilder('node')
->view($node, $node->scs_view_mode);
// Strip out contextual links
unset($build['#contextual_links']['node']);
$vars['nodes'][$nid] = $build;
}
}
/**
* Theme the Table of Contents.
*/
function theme_scs_toc($vars) {
$titles = array();
foreach ($vars['nodes'] as $node) {
$titles[] = $node->title;
}
return theme('item_list', array(
'items' => $titles,
'title' => t('Table of Contents'),
));
}
Functions
Name![]() |
Description |
---|---|
template_preprocess_scs_newsletter | Preprocess for scs_newsletter. |
theme_scs_sortable_table | Theme the node selection form. |
theme_scs_toc | Theme the Table of Contents. |