mirror of
https://github.com/farmOS/farmOS.git
synced 2024-02-23 11:37:38 +01:00
Refactor hook_farm_metrics to use a 'key' to identify arrays of metrics.
Without this, the 'farm_metrics.json' endpoint returns an array indexed by element ID, which would be more difficult for consumers of the 'farm_metrics.json' API to parse.
This commit is contained in:
parent
ec82d5d9d6
commit
b7cb769191
|
@ -15,7 +15,7 @@ function farm_area_farm_metrics() {
|
|||
// Count the number of areas.
|
||||
$areas = db_query("SELECT COUNT(tid) FROM {taxonomy_term_data} t LEFT JOIN {taxonomy_vocabulary} v ON t.vid = v.vid WHERE v.machine_name = 'farm_areas'")->fetchField();
|
||||
if (!empty($areas)) {
|
||||
$metrics[] = array(
|
||||
$metrics['areas'] = array(
|
||||
'label' => t('Areas'),
|
||||
'value' => $areas,
|
||||
'link' => 'farm/areas',
|
||||
|
@ -51,7 +51,7 @@ function farm_area_farm_metrics() {
|
|||
}
|
||||
|
||||
// Add a metric.
|
||||
$metrics[] = array(
|
||||
$metrics[$area_type] = array(
|
||||
'label' => t('@area_type area', array('@area_type' => $label)),
|
||||
'value' => $total_area,
|
||||
'link' => 'farm/areas',
|
||||
|
|
|
@ -25,22 +25,25 @@
|
|||
* Defines farm metrics.
|
||||
*
|
||||
* @return array
|
||||
* Returns an array of metrics. Each should
|
||||
* be an array containing the following keys:
|
||||
* Returns an array of farm metrics. The key should be a unique metric
|
||||
* name, and each should be an array of metric values including the
|
||||
* following keys:
|
||||
* - label: Translated metric label.
|
||||
* - value: The metric's value.
|
||||
* - link: A path to link the value to.
|
||||
* - weight: Weight for ordering (optional - defaults to alphabetical).
|
||||
*/
|
||||
function hook_farm_metrics() {
|
||||
return array(
|
||||
array(
|
||||
'label' => t('Example'),
|
||||
'value' => '100',
|
||||
'link' => 'farm/example',
|
||||
'weight' => -10,
|
||||
),
|
||||
$metrics = array();
|
||||
|
||||
$metrics['example'] = array(
|
||||
'label' => t('Example'),
|
||||
'value' => '100',
|
||||
'link' => 'farm/example',
|
||||
'weight' => -10,
|
||||
);
|
||||
|
||||
return $metrics;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -35,7 +35,7 @@ function farm_ui_farm_metrics() {
|
|||
}
|
||||
|
||||
// Build a metric.
|
||||
$metrics[] = array(
|
||||
$metrics[$type] = array(
|
||||
'label' => $info['label_plural'],
|
||||
'value' => $count,
|
||||
'link' => farm_ui_view_page_path($info['view']),
|
||||
|
|
Loading…
Reference in a new issue