function template_preprocess_site_map in Site map 8
Same name and namespace in other branches
- 6.2 site_map.theme.inc \template_preprocess_site_map()
- 7 includes/site_map.theme.inc \template_preprocess_site_map()
Preprocesses the variables for site-map.html.twig.
See also
File
- ./
site_map.theme.inc, line 151 - Site map theme functions.
Code
function template_preprocess_site_map(array &$variables) {
$config = \Drupal::config('site_map.settings');
$message = $config
->get('message.value');
if (!empty($message)) {
$variables['message'] = [
'#markup' => $message,
];
}
if ($config
->get('show_rss_links') != 0 && \Drupal::service('module_handler')
->moduleExists('commentrss') && \Drupal::config('commentrss.settings')
->get('commentrss_site')) {
$rss_legend = array(
'#theme' => 'site_map_rss_legend',
);
$variables['rss_legend'] = drupal_render($rss_legend);
}
if ($config
->get('show_titles')) {
$variables['show_titles'] = TRUE;
}
$variables['site_map_items'] = [];
$site_map_order = $config
->get('order');
asort($site_map_order);
foreach ($site_map_order as $content => $weight) {
// Get type of content.
$type = substr($content, 0, strpos($content, '_'));
$id = substr($content, strpos($content, '_') + 1);
if (empty($type)) {
$type = $content;
$id = NULL;
}
switch ($type) {
case 'front':
if ($config
->get('show_front')) {
$variables['site_map_items']['front'] = _site_map_front_page();
}
break;
case 'books':
$books = $config
->get('show_books');
if (!empty($books)) {
$variables['site_map_items']['books'] = _site_map_books();
}
break;
case 'menus':
$menus = array_filter($config
->get('show_menus'));
if (!empty($menus[$id])) {
$variables['site_map_items']['menus'][] = array(
'#markup' => _site_map_menus($id),
);
}
break;
case 'vocabularies':
$vocabulary = \Drupal::entityManager()
->getStorage('taxonomy_vocabulary')
->load($id);
$vocabularies = $config
->get('show_vocabularies');
if (!empty($vocabularies[$vocabulary
->id()])) {
// Compile the vocabulary trees.
$variables['site_map_items']['vocabularies'][] = \Drupal::service('site_map.helper')
->getTerms($vocabulary);
}
break;
}
}
// Invoke all custom modules and integrate themed HTML into the site map.
$additional = \Drupal::service('module_handler')
->invokeAll('site_map');
foreach ($additional as $themed_site_map_code) {
$variables['additional'] = $themed_site_map_code;
}
}