Use farm_fields_dynamic to create the data field (in a new module).
This commit is contained in:
parent
749ac0458f
commit
d53d67d047
|
@ -32,6 +32,7 @@ function farm_modules() {
|
|||
'farm_crop_area_types' => t('Crop area types: Bed and Greenhouse'),
|
||||
'farm_livestock_area_types' => t('Livestock area types: Paddock'),
|
||||
'farm_water' => st('Water area type'),
|
||||
'farm_data_field' => st('Add an arbitrary "data" field to logs and assets'),
|
||||
'farm_access_roles' => st('Default roles: Manager, Worker, Viewer'),
|
||||
'farm_help' => st('farmOS Help Pages'),
|
||||
'farm_tour' => st('farmOS Tours'),
|
||||
|
@ -793,6 +794,13 @@ function farm_update_7046(&$sandbox) {
|
|||
db_query("DELETE FROM {system} WHERE name = 'role_delegation' AND type = 'module'");
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an arbitrary data field to logs and assets.
|
||||
*/
|
||||
function farm_update_7047(&$sandbox) {
|
||||
_farm_update_enable_modules(array('farm_data_field'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update helper function: enable modules.
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
name = Farm Data Field
|
||||
description = Adds an arbitrary data field to logs and assets.
|
||||
core = 7.x
|
||||
package = farmOS
|
||||
dependencies[] = farm_asset
|
||||
dependencies[] = farm_fields_dynamic
|
||||
dependencies[] = log
|
||||
dependencies[] = text
|
|
@ -1,20 +1,16 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Farm fields install file.
|
||||
* Farm data field module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Add data field to logs.
|
||||
* Implements hook_farm_fields_dynamic_bases().
|
||||
*/
|
||||
function farm_fields_update_7000(&$sandbox) {
|
||||
|
||||
// Load field types.
|
||||
$field_types = field_info_fields();
|
||||
|
||||
// Create the data field base, if it doesn't already exist.
|
||||
if (empty($field_types['field_farm_data'])) {
|
||||
$field_base = array(
|
||||
function farm_data_field_farm_fields_dynamic_bases() {
|
||||
return array(
|
||||
'field_farm_data' => array(
|
||||
'active' => 1,
|
||||
'cardinality' => 1,
|
||||
'deleted' => 0,
|
||||
|
@ -30,12 +26,17 @@ function farm_fields_update_7000(&$sandbox) {
|
|||
'settings' => array(),
|
||||
'translatable' => 0,
|
||||
'type' => 'text_long',
|
||||
);
|
||||
field_create_field($field_base);
|
||||
}
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Load field instances.
|
||||
$field_instances = field_info_instances();
|
||||
/**
|
||||
* 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();
|
||||
|
@ -56,14 +57,7 @@ function farm_fields_update_7000(&$sandbox) {
|
|||
// Add a data field to each bundle.
|
||||
foreach ($entity_types as $entity_type => $bundles) {
|
||||
foreach ($bundles as $bundle) {
|
||||
|
||||
// If the instance already exists, skip it.
|
||||
if (!empty($field_instances[$entity_type][$bundle]['field_farm_data'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Create the field instance.
|
||||
$field_instance = array(
|
||||
$field_instances[] = array(
|
||||
'bundle' => $bundle,
|
||||
'default_value' => NULL,
|
||||
'deleted' => 0,
|
||||
|
@ -93,7 +87,9 @@ function farm_fields_update_7000(&$sandbox) {
|
|||
'weight' => 0,
|
||||
),
|
||||
);
|
||||
field_create_instance($field_instance);
|
||||
}
|
||||
}
|
||||
|
||||
// Return the array of field instance definitions.
|
||||
return $field_instances;
|
||||
}
|
|
@ -43,25 +43,6 @@ function farm_fields_field_default_field_bases() {
|
|||
'type' => 'entityreference',
|
||||
);
|
||||
|
||||
// Exported field_base: 'field_farm_data'.
|
||||
$field_bases['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',
|
||||
);
|
||||
|
||||
// Exported field_base: 'field_farm_date'.
|
||||
$field_bases['field_farm_date'] = array(
|
||||
'active' => 1,
|
||||
|
|
|
@ -1,66 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @file
|
||||
* farm_fields.features.field_instance.inc
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_field_default_field_instances().
|
||||
*/
|
||||
function farm_fields_field_default_field_instances() {
|
||||
$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['log-' . $bundle . '-field_farm_data'] = 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 $field_instances;
|
||||
}
|
|
@ -18,7 +18,6 @@ dependencies[] = text
|
|||
features[ctools][] = strongarm:strongarm:1
|
||||
features[features_api][] = api:2
|
||||
features[field_base][] = field_farm_asset
|
||||
features[field_base][] = field_farm_data
|
||||
features[field_base][] = field_farm_date
|
||||
features[field_base][] = field_farm_date_range
|
||||
features[field_base][] = field_farm_description
|
||||
|
|
Loading…
Reference in New Issue