function farm_theme_preprocess_page in farmOS 7
Implements hook_preprocess_page().
File
- themes/
farm_theme/ template.php, line 467 - Farm theme template.php.
Code
function farm_theme_preprocess_page(&$vars) {
// Add JS for adding Bootstrap glyphicons throughout the UI.
$glyphicons_text = array(
t('Dashboard') => 'dashboard',
t('Calendar') => 'calendar',
t('Help') => 'question-sign',
t('Create new account') => 'user',
t('My account') => 'user',
t('Log out') => 'log-out',
t('Log in') => 'log-in',
t('Request new password') => 'lock',
t('Areas') => 'globe',
t('Assets') => 'grain',
t('Logs') => 'list',
t('People') => 'user',
t('Plans') => 'book',
);
drupal_add_js(array(
'farm_theme' => array(
'glyphicons_text' => $glyphicons_text,
),
), 'setting');
drupal_add_js(drupal_get_path('theme', 'farm_theme') . '/js/glyphicons.js');
// Add Javascript to automatically collapse the help text.
if (!empty($vars['page']['help'])) {
drupal_add_js(drupal_get_path('theme', 'farm_theme') . '/js/help.js');
}
// Split the farm dashboard into two columns, with the map on the right.
$current_path = current_path();
if ($current_path == 'farm') {
// Only proceed if the metrics group exists.
if (!empty($vars['page']['content']['system_main']['metrics'])) {
// Get a list of groups (element children).
$groups = element_children($vars['page']['content']['system_main']);
// Create left and right columns.
$vars['page']['content']['system_main']['left'] = array(
'#prefix' => '<div class="col-md-6">',
'#suffix' => '</div>',
);
$vars['page']['content']['system_main']['right'] = array(
'#prefix' => '<div class="col-md-6">',
'#suffix' => '</div>',
);
// Move the map and metrics panes to the right column (and remove them
// from the groups list).
$right_panes = array(
'plans',
'metrics',
);
foreach ($right_panes as $pane) {
if (!empty($vars['page']['content']['system_main'][$pane])) {
$vars['page']['content']['system_main']['right'][$pane] = $vars['page']['content']['system_main'][$pane];
unset($vars['page']['content']['system_main'][$pane]);
$map_key = array_search($pane, $groups);
unset($groups[$map_key]);
}
}
// Iterate through the remaining groups and move them to the left column.
foreach ($groups as $group) {
$vars['page']['content']['system_main']['left'][$group] = $vars['page']['content']['system_main'][$group];
unset($vars['page']['content']['system_main'][$group]);
}
}
}
// When the farm_areas map is added to a page (via farm_area_page_build()),
// split the page into two columns.
if (!empty($vars['page']['content']['farm_areas'])) {
// Wrap map and content in "col-md-6" class so they display in two columns.
$vars['page']['content']['farm_areas']['#prefix'] = '<div class="col-md-6">';
$vars['page']['content']['farm_areas']['#suffix'] = '</div>';
$vars['page']['content']['system_main']['#prefix'] = '<div class="col-md-6">';
$vars['page']['content']['system_main']['#suffix'] = '</div>';
}
// Remove from taxonomy term pages:
// "There is currently no content classified with this term."
if (isset($vars['page']['content']['system_main']['no_content'])) {
unset($vars['page']['content']['system_main']['no_content']);
}
// Add "Powered by farmOS" to the footer.
$vars['page']['footer']['farmos'] = array(
'#type' => 'markup',
'#prefix' => '<div style="text-align: center;"><small>',
'#markup' => t('Powered by') . ' ' . l(t('farmOS'), 'https://farmos.org'),
'#suffix' => '</small></div>',
);
}