mirror of
https://github.com/farmOS/farmOS.git
synced 2024-02-23 11:37:38 +01:00
135 lines
3.2 KiB
Text
135 lines
3.2 KiB
Text
<?php
|
|
/**
|
|
* @file
|
|
* Farm dashboard module.
|
|
*/
|
|
|
|
/**
|
|
* Implements hook_hook_info().
|
|
*/
|
|
function farm_dashboard_hook_info() {
|
|
$hooks['farm_dashboard_panes'] = array(
|
|
'group' => 'farm_dashboard',
|
|
);
|
|
return $hooks;
|
|
}
|
|
|
|
/**
|
|
* Implements hook_permission().
|
|
*/
|
|
function farm_dashboard_permission() {
|
|
return array(
|
|
'access farm dashboard' => array(
|
|
'title' => t('Access farm dashboard'),
|
|
'description' => t('Access the farm dashboard.'),
|
|
),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Implements hook_farm_access_perms().
|
|
*/
|
|
function farm_dashboard_farm_access_perms($role) {
|
|
$perms = array();
|
|
|
|
// Access farm dashboard.
|
|
$perms[] = 'access farm dashboard';
|
|
|
|
return $perms;
|
|
}
|
|
|
|
/**
|
|
* Implements hook_menu().
|
|
*/
|
|
function farm_dashboard_menu() {
|
|
|
|
$items['farm'] = array(
|
|
'title' => 'Farm',
|
|
'page callback' => 'farm_dashboard_page_callback',
|
|
'access arguments' => array('access farm dashboard'),
|
|
'type' => MENU_CALLBACK,
|
|
);
|
|
$items['farm/dashboard'] = array(
|
|
'title' => 'Dashboard',
|
|
'type' => MENU_DEFAULT_LOCAL_TASK,
|
|
'weight' => -100,
|
|
);
|
|
|
|
// Root farm configuration path.
|
|
$items['admin/config/farm'] = array(
|
|
'title' => 'Farm',
|
|
'description' => 'Configure settings for your farm.',
|
|
'page callback' => 'system_admin_menu_block_page',
|
|
'access arguments' => array('access administration pages'),
|
|
'type' => MENU_NORMAL_ITEM,
|
|
'file path' => drupal_get_path('module', 'system'),
|
|
'file' => 'system.admin.inc',
|
|
);
|
|
|
|
return $items;
|
|
}
|
|
|
|
/**
|
|
* Farm dashboard page callback.
|
|
*/
|
|
function farm_dashboard_page_callback() {
|
|
|
|
// Set the page title.
|
|
drupal_set_title('Dashboard');
|
|
|
|
// Start a build array.
|
|
$build = array();
|
|
|
|
// Ask modules for dashboard panes.
|
|
$panes = module_invoke_all('farm_dashboard_panes');
|
|
|
|
// Iterate through the panes and add them to the dashboard.
|
|
foreach ($panes as $pane) {
|
|
|
|
// Set defaults for title, output, group, and weight.
|
|
$output = '';
|
|
$title = '';
|
|
$group = 'general';
|
|
$weight = 0;
|
|
|
|
// Use the provided title, if available.
|
|
if (!empty($pane['title'])) {
|
|
$title = $pane['title'];
|
|
}
|
|
|
|
// If a 'view' and 'view_display_id' are provided, load the view, generate
|
|
// the preview, and set the title automatically.
|
|
if (!empty($pane['view']) && !empty($pane['view_display_id'])) {
|
|
$view = views_get_view($pane['view']);
|
|
$preview = $view->preview($pane['view_display_id']);
|
|
$title = $view->get_title();
|
|
$output = $preview;
|
|
}
|
|
|
|
// Or, if a callback function exists, execute it to get output.
|
|
elseif (!empty($pane['callback']) && function_exists($pane['callback'])) {
|
|
$output = call_user_func($pane['callback']);
|
|
}
|
|
|
|
// If a group is not provided, assign it to a general default group.
|
|
if (!empty($pane['group'])) {
|
|
$group = $pane['group'];
|
|
}
|
|
|
|
// If a weight is not provided, default to 0.
|
|
if (!empty($pane['weight'])) {
|
|
$weight = $pane['weight'];
|
|
}
|
|
|
|
// Assemble a markup item and add it to the build array.
|
|
$item = array(
|
|
'#type' => 'markup',
|
|
'#markup' => '<h2 id="' . drupal_html_id($title) . '">' . check_plain($title) . '</h2>' . $output,
|
|
'#weight' => $weight,
|
|
);
|
|
$build[$group][] = $item;
|
|
}
|
|
|
|
// Return the build array.
|
|
return $build;
|
|
}
|