Add a simple module for "quick forms" in farmOS, with an API hook that other modules can use to add forms.
This commit is contained in:
parent
4835354b5d
commit
595258eef0
|
@ -0,0 +1,39 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* Hooks provided by farm_quick.
|
||||||
|
*
|
||||||
|
* 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_quick Farm quick module integrations.
|
||||||
|
*
|
||||||
|
* Module integrations with the farm_quick module.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @defgroup farm_quick_hooks Farm quick's hooks
|
||||||
|
* @{
|
||||||
|
* Hooks that can be implemented by other modules in order to extend farm_quick.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define quick forms provided by this module
|
||||||
|
*/
|
||||||
|
function hook_farm_quick_forms() {
|
||||||
|
return array(
|
||||||
|
'myform' => array(
|
||||||
|
'tab' => t('My form'),
|
||||||
|
'permission' => 'create farm_harvest log entities',
|
||||||
|
'form' => 'my_quick_form',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
|
@ -0,0 +1,5 @@
|
||||||
|
name = Farm Quick Forms
|
||||||
|
description = Provides a framework for quick forms in farmOS.
|
||||||
|
core = 7.x
|
||||||
|
package = farmOS (beta)
|
||||||
|
dependencies[] = farm_dashboard
|
|
@ -0,0 +1,80 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* Code for the Farm Quick module.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load information about all quick forms provided by other modules.
|
||||||
|
*/
|
||||||
|
function farm_quick_forms() {
|
||||||
|
|
||||||
|
// Ask modules for quick forms.
|
||||||
|
$forms = module_invoke_all('farm_quick_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) {
|
||||||
|
|
||||||
|
// Add a "Quick forms" default tab for the first item.
|
||||||
|
if ($name == $first) {
|
||||||
|
$items['farm/quick'] = array(
|
||||||
|
'title' => 'Quick forms',
|
||||||
|
'page callback' => 'drupal_get_form',
|
||||||
|
'page arguments' => array($form['form']),
|
||||||
|
'access arguments' => array($form['permission']),
|
||||||
|
'type' => MENU_LOCAL_TASK,
|
||||||
|
);
|
||||||
|
$items['farm/quick/' . $name] = array(
|
||||||
|
'title' => $form['tab'],
|
||||||
|
'type' => MENU_DEFAULT_LOCAL_TASK,
|
||||||
|
);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add each remaining form as another tab.
|
||||||
|
$items['farm/quick/' . $name] = array(
|
||||||
|
'title' => $form['tab'],
|
||||||
|
'page callback' => 'drupal_get_form',
|
||||||
|
'page arguments' => array($form['form']),
|
||||||
|
'access arguments' => array($form['permission']),
|
||||||
|
'type' => MENU_LOCAL_TASK,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return menu items.
|
||||||
|
return $items;
|
||||||
|
}
|
Loading…
Reference in New Issue