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

Add hook_farm_log_prepopulate_reference_fields() to allow modules to provide information about fields that can be prepopulated in log forms.

This commit is contained in:
Michael Stenta 2018-02-22 11:13:47 -05:00
parent a0e93dac4e
commit 2550e19f8d
2 changed files with 32 additions and 7 deletions

View file

@ -60,6 +60,22 @@ function hook_farm_log_categories_populate($log) {
return $categories;
}
/**
* Allow modules to provide information about fields that should be
* prepopulated in log forms.
*
* @return array
* Returns an array of field information.
*/
function hook_farm_log_prepopulate_reference_fields() {
return array(
'field_farm_asset' => array(
'entity_type' => 'farm_asset',
'url_param' => 'farm_asset',
),
);
}
/**
* @}
*/

View file

@ -325,15 +325,12 @@ function farm_log_prepopulate_log_form_name(&$form) {
}
/**
* Helper function for populating entity reference fields in log forms.
*
* @param array $form
* The form array to modify, passed by reference.
* Implements hook_farm_log_prepopulate_reference_fields().
*/
function farm_log_prepopulate_log_form_references(&$form) {
function farm_log_farm_log_prepopulate_reference_fields() {
// Define the fields we will be populating.
$fields = array(
// Define the fields that will be prepopulated in log forms.
return array(
'field_farm_asset' => array(
'entity_type' => 'farm_asset',
'url_param' => 'farm_asset',
@ -352,6 +349,18 @@ function farm_log_prepopulate_log_form_references(&$form) {
'entity_type' => 'user',
),
);
}
/**
* Helper function for populating entity reference fields in log forms.
*
* @param array $form
* The form array to modify, passed by reference.
*/
function farm_log_prepopulate_log_form_references(&$form) {
// Ask modules for information about fields that should be prepopulated.
$fields = module_invoke_all('farm_log_prepopulate_reference_fields');
// Populate the fields.
foreach ($fields as $field => $info) {