Init farm_metrics modules from existing farm_dashboard code.

This commit is contained in:
Paul Weidner 2020-01-15 09:23:44 -08:00 committed by Michael Stenta
parent 6611a52cb7
commit 7ee3c604a4
5 changed files with 73 additions and 28 deletions

View File

@ -50,28 +50,6 @@ function hook_farm_dashboard_panes() {
);
}
/**
* Defines farm dashboard metrics.
*
* @return array
* Returns an array of metrics to be displays on the dashboard. Each should
* be an array containing 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_dashboard_metrics() {
return array(
array(
'label' => t('Example'),
'value' => '100',
'link' => 'farm/example',
'weight' => -10,
),
);
}
/**
* @}
*/

View File

@ -0,0 +1,48 @@
<?php
/**
* @file
* Hooks provided by farm_metrics.
*
* This file contains no working PHP code; it exists to provide additional
* documentation for doxygen as well as to document hooks in the standard
* Drupal manner.
*/
/**
* @defgroup farm_metrics Farm metrics module integrations.
*
* Module integrations with the farm_metrics module.
*/
/**
* @defgroup farm_metrics_hooks Farm metrics's hooks
* @{
* Hooks that can be implemented by other modules in order to extend farm_metrics.
*/
/**
* Defines farm metrics.
*
* @return array
* Returns an array of metrics. Each should
* be an array containing 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,
),
);
}
/**
* @}
*/

View File

@ -1,17 +1,17 @@
<?php
/**
* @file
* Farm dashboard hooks implemented by farm_dashboard module.
* Farm dashboard hooks implemented by farm_metrics module.
*/
/**
* Implements hook_farm_dashboard_panes().
*/
function farm_dashboard_farm_dashboard_panes() {
function farm_metrics_farm_dashboard_panes() {
return array(
'farm_dashboard_metrics' => array(
'farm_metrics' => array(
'title' => t('Metrics'),
'callback' => 'farm_dashboard_metrics',
'callback' => 'farm_metrics_dashboard_pane',
'group' => 'metrics',
),
);
@ -20,10 +20,10 @@ function farm_dashboard_farm_dashboard_panes() {
/**
* Metrics dashboard callback.
*/
function farm_dashboard_metrics() {
function farm_metrics_dashboard_pane() {
// Ask modules for metrics.
$metrics = module_invoke_all('farm_dashboard_metrics');
$metrics = module_invoke_all('farm_metrics');
if (empty($metrics)) {
return 'No metrics available.';
}

View File

@ -0,0 +1,4 @@
name = Farm Metrics
description = Allow modules to define high level metrics.
core = 7.x
package = farmOS

View File

@ -0,0 +1,15 @@
<?php
/**
* @file
* Farm metrics module.
*/
/**
* Implements hook_hook_info().
*/
function farm_metrics_hook_info() {
$hooks['farm_metrics'] = array(
'group' => 'farm_metrics',
);
return $hooks;
}