3
0
Fork 0
mirror of https://github.com/farmOS/farmOS.git synced 2024-02-23 11:37:38 +01:00
farmOS/modules/farm/farm_quick/farm_quick.module

106 lines
2.5 KiB
Plaintext
Raw Normal View History

<?php
/**
* @file
* Code for the Farm Quick module.
*/
/**
* Implements hook_hook_info().
*/
function farm_quick_hook_info() {
$hooks['farm_quick_forms'] = array(
'group' => 'farm_quick',
);
return $hooks;
}
/**
* Load information about all quick forms provided by other modules.
*/
function farm_quick_forms() {
// Ask modules for quick forms.
$forms = array();
$modules = module_implements('farm_quick_forms');
foreach ($modules as $module) {
$module_forms = module_invoke($module, 'farm_quick_forms');
foreach ($module_forms as &$form) {
$form['module'] = $module;
}
$forms = array_merge($forms, $module_forms);
}
// Sort the quick forms.
uasort($forms, 'farm_quick_forms_sort');
// Return the array of quick forms.
return $forms;
}
/**
* Sort function for quick form definitions.
*/
function farm_quick_forms_sort($a, $b) {
// Sort alphabetically by the 'tab' property.
return strcasecmp($a['tab'], $b['tab']);
}
/**
* Implements hook_menu().
*/
function farm_quick_menu() {
// Start with an empty menu items array.
$items = array();
// Ask for quick forms from modules.
$forms = farm_quick_forms();
// If there are no forms, bail.
if (empty($forms)) {
return $items;
}
// Add a menu item for each form.
reset($forms);
$first = key($forms);
foreach ($forms as $name => $form) {
// Build a menu item definition.
$menu_item = array(
'title' => $form['tab'],
'page callback' => 'drupal_get_form',
'page arguments' => array($form['form']),
'access arguments' => array($form['permission']),
'type' => MENU_LOCAL_TASK,
);
// If the quick form code is in a separate file, add that information
// to the menu item so Drupal knows where to look.
if (!empty($form['file']) && !empty($form['module'])) {
$menu_item['file'] = $form['file'];
$menu_item['file path'] = drupal_get_path('module', $form['module']);
}
// If this is the first item, make it the default tab for "Quick forms".
if ($name == $first) {
$items['farm/quick'] = $menu_item;
$items['farm/quick']['title'] = 'Quick forms';
$items['farm/quick']['type'] = MENU_LOCAL_TASK;
$items['farm/quick/' . $name] = array(
'title' => $menu_item['title'],
'type' => MENU_DEFAULT_LOCAL_TASK,
);
}
// Otherwise, treat it as a normal menu tab.
else {
$items['farm/quick/' . $name] = $menu_item;
}
}
// Return menu items.
return $items;
}