Add area links for some log types.
This commit is contained in:
parent
ee811350e3
commit
51f5cb906e
|
@ -41,23 +41,3 @@ function farm_log_activity_farm_taxonomy_term_view_views($term) {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Implements hook_farm_area_links().
|
|
||||||
*/
|
|
||||||
function farm_log_activity_farm_area_links($id) {
|
|
||||||
$links = array();
|
|
||||||
|
|
||||||
// Add link to activities.
|
|
||||||
$view = views_get_view('farm_log_activity');
|
|
||||||
$view->preview('default', array('all', $id));
|
|
||||||
if ($view->total_rows > 0) {
|
|
||||||
$links[] = array(
|
|
||||||
'title' => t('Activities') . ': ' . $view->total_rows,
|
|
||||||
'href' => 'farm/logs/activities/all/' . $id,
|
|
||||||
'weight' => -100,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $links;
|
|
||||||
}
|
|
||||||
|
|
|
@ -41,23 +41,3 @@ function farm_log_input_farm_taxonomy_term_view_views($term) {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Implements hook_farm_area_links().
|
|
||||||
*/
|
|
||||||
function farm_log_input_farm_area_links($id) {
|
|
||||||
$links = array();
|
|
||||||
|
|
||||||
// Add link to inputs.
|
|
||||||
$view = views_get_view('farm_log_input');
|
|
||||||
$view->preview('default', array('all', $id));
|
|
||||||
if ($view->total_rows > 0) {
|
|
||||||
$links[] = array(
|
|
||||||
'title' => t('Inputs') . ': ' . $view->total_rows,
|
|
||||||
'href' => 'farm/logs/inputs/all/' . $id,
|
|
||||||
'weight' => 10,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $links;
|
|
||||||
}
|
|
||||||
|
|
|
@ -43,23 +43,3 @@ function farm_log_observation_farm_taxonomy_term_view_views($term) {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Implements hook_farm_area_links().
|
|
||||||
*/
|
|
||||||
function farm_log_observation_farm_area_links($id) {
|
|
||||||
$links = array();
|
|
||||||
|
|
||||||
// Add link to observations.
|
|
||||||
$view = views_get_view('farm_log_observation');
|
|
||||||
$view->preview('default', array('all', $id));
|
|
||||||
if ($view->total_rows > 0) {
|
|
||||||
$links[] = array(
|
|
||||||
'title' => t('Observations') . ': ' . $view->total_rows,
|
|
||||||
'href' => 'farm/logs/observations/all/' . $id,
|
|
||||||
'weight' => -100,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $links;
|
|
||||||
}
|
|
||||||
|
|
|
@ -38,22 +38,3 @@ function farm_soil_test_farm_taxonomy_term_view_views($term) {
|
||||||
'farm_log_soil_tests',
|
'farm_log_soil_tests',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Implements hook_farm_area_links().
|
|
||||||
*/
|
|
||||||
function farm_soil_test_farm_area_links($id) {
|
|
||||||
$links = array();
|
|
||||||
|
|
||||||
// Add link to soil tests.
|
|
||||||
$view = views_get_view('farm_log_soil_tests');
|
|
||||||
$view->preview('default', array($id));
|
|
||||||
if ($view->total_rows > 0) {
|
|
||||||
$links[] = array(
|
|
||||||
'title' => t('Soil tests') . ': ' . $view->total_rows,
|
|
||||||
'href' => 'farm/logs/soil-tests/' . $id,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $links;
|
|
||||||
}
|
|
||||||
|
|
|
@ -73,7 +73,8 @@ function hook_farm_ui_entities() {
|
||||||
'farm_asset' => 'planting',
|
'farm_asset' => 'planting',
|
||||||
|
|
||||||
// Set 'areas' to TRUE if the log type can be used on areas.
|
// Set 'areas' to TRUE if the log type can be used on areas.
|
||||||
// This will add an action link on area pages.
|
// This will add an action link on area pages, and will show a link in
|
||||||
|
// the area details popup.
|
||||||
'areas' => TRUE,
|
'areas' => TRUE,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
@ -526,5 +526,59 @@ function farm_ui_farm_area_links($id) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add area links for some log types.
|
||||||
|
if (!empty($ui_info['log'])) {
|
||||||
|
foreach ($ui_info['log'] as $log_type => $info) {
|
||||||
|
|
||||||
|
// Only proceed if the log type has 'areas' set to TRUE.
|
||||||
|
if (empty($info['areas']) || $info['areas'] !== TRUE) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If a View is not available, skip it.
|
||||||
|
if (empty($info['view'])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Log View arguments are a bit more complicated than Asset Views. Most
|
||||||
|
// logs apply to assets, so have an asset contextual filter first, and an
|
||||||
|
// area contextual filter second. Some logs do not apply to assets, so
|
||||||
|
// the first contextual filter is the area ID. The pattern we follow here
|
||||||
|
// is: if the entity UI info has 'farm_asset' set to 'none', then we
|
||||||
|
// assume that 'area ID' is the first argument. Otherwise, we assume that
|
||||||
|
// 'asset ID' is the first, and 'area ID' is the second. In the case of
|
||||||
|
// area links, we only care about the 'area ID', so we set the 'asset ID'
|
||||||
|
// argument to 'all'.
|
||||||
|
if ($info['farm_asset'] == 'none') {
|
||||||
|
$args = array($id);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$args = array('all', $id);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load the View and generate a preview to count rows.
|
||||||
|
$view = views_get_view($info['view']);
|
||||||
|
$view->preview('default', $args);
|
||||||
|
|
||||||
|
// If there are no results, skip it.
|
||||||
|
if (empty($view->total_rows)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build the View page path with arguments.
|
||||||
|
$path = farm_ui_view_page_path($info['view']);
|
||||||
|
foreach ($args as $arg) {
|
||||||
|
$path .= '/' . $arg;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build a link.
|
||||||
|
$links[] = array(
|
||||||
|
'title' => $info['label_plural'] . ': ' . $view->total_rows,
|
||||||
|
'href' => $path,
|
||||||
|
'weight' => 10,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $links;
|
return $links;
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,22 +38,3 @@ function farm_water_test_farm_taxonomy_term_view_views($term) {
|
||||||
'farm_water_test',
|
'farm_water_test',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Implements hook_farm_area_links().
|
|
||||||
*/
|
|
||||||
function farm_water_test_farm_area_links($id) {
|
|
||||||
$links = array();
|
|
||||||
|
|
||||||
// Add link to water tests.
|
|
||||||
$view = views_get_view('farm_water_test');
|
|
||||||
$view->preview('default', array($id));
|
|
||||||
if ($view->total_rows > 0) {
|
|
||||||
$links[] = array(
|
|
||||||
'title' => t('Water tests') . ': ' . $view->total_rows,
|
|
||||||
'href' => 'farm/logs/water-tests/' . $id,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $links;
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue