Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #3046929: Arbitrary data field on assets and logs
- Loading branch information
Showing
15 changed files
with
218 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
modules/farm/farm_fields/farm_fields.features.field_instance.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<?php | ||
/** | ||
* @file | ||
* Farm fields install file. | ||
*/ | ||
|
||
/** | ||
* Add data field to logs. | ||
*/ | ||
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( | ||
'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', | ||
); | ||
field_create_field($field_base); | ||
} | ||
|
||
// Load field instances. | ||
$field_instances = field_info_instances(); | ||
|
||
// 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) { | ||
|
||
// 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( | ||
'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, | ||
), | ||
); | ||
field_create_instance($field_instance); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters