2015-02-26 17:51:27 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @file
|
2015-04-10 23:06:02 +02:00
|
|
|
* Farm theme template.php.
|
2015-02-26 17:51:27 +01:00
|
|
|
*/
|
2015-02-26 20:28:05 +01:00
|
|
|
|
2016-02-01 00:41:40 +01:00
|
|
|
/**
|
2016-02-02 16:26:15 +01:00
|
|
|
* Implements hook_menu_link_alter().
|
2016-02-01 00:41:40 +01:00
|
|
|
*/
|
|
|
|
function farm_theme_menu_link_alter(&$item) {
|
|
|
|
|
|
|
|
// Expand top-level menu link items by default.
|
|
|
|
$paths = array(
|
|
|
|
'farm/assets',
|
|
|
|
'farm/logs',
|
|
|
|
);
|
|
|
|
if (in_array($item['link_path'], $paths)) {
|
|
|
|
$item['expanded'] = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-26 20:28:05 +01:00
|
|
|
/**
|
2017-04-20 22:13:16 +02:00
|
|
|
* Implements hook_field_widget_form_alter().
|
2015-02-26 20:28:05 +01:00
|
|
|
*/
|
2017-04-20 22:13:16 +02:00
|
|
|
function farm_theme_field_widget_form_alter(&$element, &$form_state, $context) {
|
2015-10-02 02:55:18 +02:00
|
|
|
|
2017-05-19 22:30:42 +02:00
|
|
|
// The code below will be used to make certain fieldsets collapsible.
|
|
|
|
// Collapsing them will be done via Javascript, instead of PHP, however,
|
|
|
|
// because of an outstanding issue with rendering Openlayers maps in collapsed
|
|
|
|
// fieldsets. The $collapse_js boolean variable will keep track of whether or
|
|
|
|
// not the Javascript is necessary in the current page, and will add it at the
|
|
|
|
// bottom of this function. The Javascript works by looking for a CSS class
|
|
|
|
// called 'farm-theme-collapse' on the fieldsets, and collapses them.
|
|
|
|
/**
|
|
|
|
* @todo
|
|
|
|
* Revert to using normal PHP `['collapsed'] = TRUE;` when the following
|
|
|
|
* issues are fixed.
|
|
|
|
*
|
|
|
|
* @see https://www.drupal.org/node/2644580
|
|
|
|
* @see https://www.drupal.org/node/2579009
|
|
|
|
*/
|
|
|
|
$collapse_js = FALSE;
|
|
|
|
|
|
|
|
// Put geofields into a collapsible fieldset.
|
2017-04-20 22:13:16 +02:00
|
|
|
if ($context['field']['type'] == 'geofield') {
|
2015-12-01 19:11:32 +01:00
|
|
|
|
2017-05-18 22:25:58 +02:00
|
|
|
// Exception: do not collapse geofields when adding/editing areas.
|
|
|
|
if (!empty($context['form']['#term']) && $context['form']['#term']['vocabulary_machine_name'] == 'farm_areas') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-04-20 22:13:16 +02:00
|
|
|
// Iterate through all the element children.
|
|
|
|
$children = element_children($element);
|
|
|
|
foreach ($children as $child) {
|
2016-10-26 17:53:38 +02:00
|
|
|
|
2017-04-20 22:13:16 +02:00
|
|
|
// Make the parent element into a collapsible fieldset.
|
|
|
|
$element[$child]['#type'] = 'fieldset';
|
|
|
|
$element[$child]['#collapsible'] = TRUE;
|
2017-05-19 22:30:42 +02:00
|
|
|
$element[$child]['#attributes']['class'][] = 'farm-theme-collapse';
|
|
|
|
$collapse_js = TRUE;
|
2015-10-02 02:55:18 +02:00
|
|
|
}
|
2017-05-19 22:30:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Collapse field collection fieldsets by default.
|
|
|
|
elseif ($context['field']['type'] == 'field_collection') {
|
|
|
|
$element['#collapsible'] = TRUE;
|
|
|
|
$element['#attributes']['class'][] = 'farm-theme-collapse';
|
|
|
|
$collapse_js = TRUE;
|
|
|
|
}
|
2017-04-20 22:13:16 +02:00
|
|
|
|
2017-05-19 22:30:42 +02:00
|
|
|
// Add Javascript to collapse fieldsets.
|
|
|
|
if ($collapse_js) {
|
|
|
|
drupal_add_js(drupal_get_path('theme', 'farm_theme') . '/js/collapse.js');
|
2015-10-02 02:55:18 +02:00
|
|
|
}
|
2017-04-20 22:13:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements hook_form_alter().
|
|
|
|
*/
|
|
|
|
function farm_theme_form_alter(&$form, &$form_state, $form_id) {
|
2015-10-02 02:55:18 +02:00
|
|
|
|
2015-03-12 16:44:45 +01:00
|
|
|
// Views Exposed (filters and sort) form:
|
2017-04-20 22:13:16 +02:00
|
|
|
if ($form_id == 'views_exposed_form') {
|
2015-02-26 20:28:05 +01:00
|
|
|
|
2015-09-07 17:10:08 +02:00
|
|
|
/* Wrap the exposed form in a Bootstrap collapsible panel. */
|
|
|
|
|
|
|
|
// Collapsible panel ID.
|
|
|
|
$panel_head_id = $form['#id'] . '-panel-heading';
|
|
|
|
$panel_body_id = $form['#id'] . '-panel-body';
|
|
|
|
|
|
|
|
// Collapse by default.
|
|
|
|
$collapse = TRUE;
|
2015-09-08 02:08:34 +02:00
|
|
|
|
2015-09-07 17:10:08 +02:00
|
|
|
// If the form was submitted (if there are values in $_GET other than 'q'),
|
|
|
|
// do not collapse the form.
|
|
|
|
if (count($_GET) > 1) {
|
|
|
|
$collapse = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set attributes depending on the collapsed state (used in HTML below).
|
|
|
|
if ($collapse) {
|
|
|
|
$collapse_class = '';
|
|
|
|
$aria_expanded = 'false';
|
|
|
|
} else {
|
|
|
|
$collapse_class = ' in';
|
|
|
|
$aria_expanded = 'true';
|
|
|
|
}
|
2015-02-26 20:28:05 +01:00
|
|
|
|
|
|
|
// Form prefix HTML:
|
|
|
|
$form['#prefix'] = '
|
2017-07-10 15:40:53 +02:00
|
|
|
<fieldset class="panel panel-default collapsible">
|
|
|
|
<legend class="panel-heading" role="tab" id="' . $panel_head_id . '">
|
|
|
|
<a class="panel-title fieldset-legend collapsed" data-toggle="collapse" href="#' . $panel_body_id . '" aria-expanded="' . $aria_expanded . '" aria-controls="' . $panel_body_id . '">
|
|
|
|
Filter/Sort
|
|
|
|
</a>
|
|
|
|
</legend>
|
2015-09-07 17:10:08 +02:00
|
|
|
<div id="' . $panel_body_id . '" class="panel-collapse collapse' . $collapse_class . '" role="tabpanel" aria-labelledby="' . $panel_head_id . '">
|
2015-02-26 20:28:05 +01:00
|
|
|
<div class="panel-body">';
|
|
|
|
|
|
|
|
// Form suffix HTML:
|
|
|
|
$form['#suffix'] = '
|
|
|
|
</div>
|
|
|
|
</div>
|
2017-07-10 15:40:53 +02:00
|
|
|
</fieldset>';
|
2015-02-26 20:28:05 +01:00
|
|
|
}
|
2015-04-08 23:19:09 +02:00
|
|
|
}
|
2015-02-26 20:28:27 +01:00
|
|
|
|
2015-04-08 23:19:09 +02:00
|
|
|
/**
|
|
|
|
* Implements hook_views_bulk_operations_form_alter().
|
|
|
|
*/
|
|
|
|
function farm_theme_views_bulk_operations_form_alter(&$form, &$form_state, $vbo) {
|
2015-03-12 16:44:45 +01:00
|
|
|
|
2015-04-08 23:19:09 +02:00
|
|
|
// Add some JavaScript to hide the VBO buttons until items are selected.
|
|
|
|
drupal_add_js(drupal_get_path('theme', 'farm_theme') . '/js/vbo.js');
|
2015-03-12 16:44:45 +01:00
|
|
|
|
2015-04-08 23:19:09 +02:00
|
|
|
// Move VBO buttons to the bottom.
|
|
|
|
$form['select']['#weight'] = 100;
|
2015-04-08 23:37:13 +02:00
|
|
|
|
|
|
|
// Move the "Clone" action to the end of the list.
|
|
|
|
if (!empty($form['select']['action::log_clone_action'])) {
|
|
|
|
$form['select']['action::log_clone_action']['#weight'] = 100;
|
|
|
|
}
|
2017-07-11 12:06:14 +02:00
|
|
|
}
|
2015-04-09 00:01:03 +02:00
|
|
|
|
2017-07-11 12:06:14 +02:00
|
|
|
/**
|
|
|
|
* Implements hook_bootstrap_colorize_text_alter().
|
|
|
|
*/
|
|
|
|
function farm_theme_bootstrap_colorize_text_alter(&$texts) {
|
|
|
|
|
|
|
|
// Colorize VBO action buttons.
|
|
|
|
$texts['matches'][t('Move')] = 'default';
|
|
|
|
$texts['matches'][t('Done')] = 'success';
|
|
|
|
$texts['matches'][t('Not Done')] = 'danger';
|
|
|
|
$texts['matches'][t('Reschedule')] = 'warning';
|
|
|
|
$texts['matches'][t('Clone')] = 'default';
|
2015-02-26 20:28:05 +01:00
|
|
|
}
|
2015-03-21 15:02:53 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements hook_entity_view_alter().
|
|
|
|
*/
|
|
|
|
function farm_theme_entity_view_alter(&$build, $type) {
|
|
|
|
|
|
|
|
// If the entity is not a farm_asset, bail.
|
|
|
|
if ($type != 'farm_asset') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-09-28 23:58:13 +02:00
|
|
|
// Float the location information to the right.
|
|
|
|
if (!empty($build['location'])) {
|
2015-03-21 15:02:53 +01:00
|
|
|
|
|
|
|
// Wrap it in a floated div.
|
2015-09-28 23:58:13 +02:00
|
|
|
$build['location']['#prefix'] = '<div class="col-md-6">';
|
|
|
|
$build['location']['#suffix'] = '</div>';
|
|
|
|
$build['location']['#weight'] = -99;
|
2015-03-21 15:02:53 +01:00
|
|
|
|
|
|
|
// Put everything else into another div and move it to the top so it
|
|
|
|
// aligns left.
|
|
|
|
$build['fields'] = array(
|
|
|
|
'#prefix' => '<div class="col-md-6">',
|
|
|
|
'#suffix' => '</div>',
|
|
|
|
'#weight' => -100,
|
|
|
|
);
|
|
|
|
$elements = element_children($build);
|
|
|
|
foreach ($elements as $element) {
|
2015-09-28 23:58:13 +02:00
|
|
|
if (!in_array($element, array('location', 'fields', 'views'))) {
|
2015-03-21 15:02:53 +01:00
|
|
|
$build['fields'][$element] = $build[$element];
|
|
|
|
unset($build[$element]);
|
|
|
|
}
|
|
|
|
}
|
2015-09-28 23:58:13 +02:00
|
|
|
|
|
|
|
// Wrap the Views in a full-width div at the bottom.
|
|
|
|
if (!empty($build['views'])) {
|
|
|
|
$build['views']['#prefix'] = '<div class="col-md-12">';
|
|
|
|
$build['views']['#suffix'] = '</div>';
|
|
|
|
$build['views']['#weight'] = 101;
|
|
|
|
}
|
2015-03-21 15:02:53 +01:00
|
|
|
}
|
2015-03-21 15:03:30 +01:00
|
|
|
}
|
|
|
|
|
2016-08-08 17:16:42 +02:00
|
|
|
/**
|
|
|
|
* Implements hook_page_alter().
|
|
|
|
*/
|
|
|
|
function farm_theme_page_alter(&$page) {
|
|
|
|
|
|
|
|
// If an access denied page is displayed and the user is not logged in...
|
|
|
|
global $user;
|
|
|
|
$status = drupal_get_http_header('status');
|
|
|
|
if ($status == '403 Forbidden' && empty($user->uid)) {
|
|
|
|
|
|
|
|
// Display a link to the user login page.
|
|
|
|
$page['content']['system_main']['login'] = array(
|
|
|
|
'#type' => 'markup',
|
|
|
|
'#markup' => '<p>' . l('Login to farmOS', 'user') . '</p>',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-21 15:03:30 +01:00
|
|
|
/**
|
|
|
|
* Implements hook_preprocess_page().
|
|
|
|
*/
|
|
|
|
function farm_theme_preprocess_page(&$vars) {
|
|
|
|
|
2015-08-08 18:09:00 +02:00
|
|
|
// When the farm_areas map is displayed on a page...
|
|
|
|
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>';
|
|
|
|
}
|
|
|
|
|
2015-03-21 15:03:30 +01:00
|
|
|
// 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']);
|
|
|
|
}
|
2015-03-27 16:15:47 +01:00
|
|
|
|
|
|
|
// Add "Powered by farmOS" to the footer.
|
2015-06-28 18:12:59 +02:00
|
|
|
$vars['page']['footer']['farmos'] = array(
|
2015-03-27 16:15:47 +01:00
|
|
|
'#type' => 'markup',
|
2015-06-28 18:12:59 +02:00
|
|
|
'#prefix' => '<div style="text-align: center;"><small>',
|
|
|
|
'#markup' => t('Powered by') . ' ' . l(t('farmOS'), 'http://farmos.org'),
|
|
|
|
'#suffix' => '</small></div>',
|
2015-03-27 16:15:47 +01:00
|
|
|
);
|
|
|
|
}
|
2015-09-29 00:27:24 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements hook_preprocess_field().
|
|
|
|
*/
|
|
|
|
function farm_theme_preprocess_field(&$vars) {
|
|
|
|
|
|
|
|
// Add a clearfix class to field_farm_images to prevent float issues.
|
|
|
|
// @see .field-name-field-farm-images .field-item in styles.css.
|
|
|
|
if ($vars['element']['#field_name'] == 'field_farm_images') {
|
|
|
|
$vars['classes_array'][] = 'clearfix';
|
|
|
|
}
|
|
|
|
}
|