118 lines
2.8 KiB
Plaintext
118 lines
2.8 KiB
Plaintext
<?php
|
|
|
|
/**
|
|
* @file
|
|
* Farm data field module.
|
|
*/
|
|
|
|
/**
|
|
* Implements hook_farm_fields_dynamic_bases().
|
|
*/
|
|
function farm_data_field_farm_fields_dynamic_bases() {
|
|
return array(
|
|
'field_farm_data' => array(
|
|
'active' => 1,
|
|
'cardinality' => 1,
|
|
'deleted' => 0,
|
|
'entity_types' => array(),
|
|
'field_name' => 'field_farm_data',
|
|
'indexes' => array(
|
|
'format' => array(
|
|
0 => 'format',
|
|
),
|
|
),
|
|
'locked' => 0,
|
|
'module' => 'text',
|
|
'settings' => array(),
|
|
'translatable' => 0,
|
|
'type' => 'text_long',
|
|
),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Implements hook_farm_fields_dynamic_instances().
|
|
*/
|
|
function farm_data_field_farm_fields_dynamic_instances() {
|
|
|
|
// Start an empty array of field instance definitions.
|
|
$field_instances = array();
|
|
|
|
// Get a list of log types.
|
|
$log_types = log_types();
|
|
|
|
// Get a list of asset types.
|
|
$asset_types = farm_asset_types();
|
|
|
|
// Iterate through the log and asset types to build an array of entity types
|
|
// and bundles.
|
|
$entity_types = array();
|
|
foreach ($log_types as $bundle => $info) {
|
|
$entity_types['log'][] = $bundle;
|
|
}
|
|
foreach ($asset_types as $bundle => $info) {
|
|
$entity_types['farm_asset'][] = $bundle;
|
|
}
|
|
|
|
// Add a data field to each bundle.
|
|
foreach ($entity_types as $entity_type => $bundles) {
|
|
foreach ($bundles as $bundle) {
|
|
$field_instances[] = array(
|
|
'bundle' => $bundle,
|
|
'default_value' => NULL,
|
|
'deleted' => 0,
|
|
'description' => t('The data field can be used to store arbitrary data on the log.'),
|
|
'display' => array(
|
|
'default' => array(
|
|
'label' => 'above',
|
|
'type' => 'hidden',
|
|
'weight' => 0,
|
|
),
|
|
),
|
|
'entity_type' => $entity_type,
|
|
'field_name' => 'field_farm_data',
|
|
'label' => t('Data'),
|
|
'required' => 0,
|
|
'settings' => array(
|
|
'text_processing' => 0,
|
|
'user_register_form' => FALSE,
|
|
),
|
|
'widget' => array(
|
|
'active' => 1,
|
|
'module' => 'text',
|
|
'settings' => array(
|
|
'rows' => 5,
|
|
),
|
|
'type' => 'text_textarea',
|
|
'weight' => 0,
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
// Return the array of field instance definitions.
|
|
return $field_instances;
|
|
}
|
|
|
|
/**
|
|
* Implements hook_form_FORM_ID_alter().
|
|
*/
|
|
function farm_data_field_form_log_form_alter(&$form, &$form_state, $form_id) {
|
|
|
|
// Hide the data field in log forms.
|
|
if (!empty($form['field_farm_data'])) {
|
|
$form['field_farm_data']['#access'] = FALSE;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Implements hook_form_FORM_ID_alter().
|
|
*/
|
|
function farm_data_field_form_farm_asset_form_alter(&$form, &$form_state, $form_id) {
|
|
|
|
// Hide the data field in asset forms.
|
|
if (!empty($form['field_farm_data'])) {
|
|
$form['field_farm_data']['#access'] = FALSE;
|
|
}
|
|
}
|