mirror of
https://github.com/farmOS/farmOS.git
synced 2024-02-23 11:37:38 +01:00
Add "equipment used" field to logs on existing sites.
This commit is contained in:
parent
e33e152f7a
commit
edb67fb77a
1 changed files with 102 additions and 0 deletions
|
@ -67,3 +67,105 @@ function farm_equipment_update_7002(&$sandbox) {
|
|||
function farm_equipment_update_7003(&$sandbox) {
|
||||
features_revert(array('farm_equipment' => array('field_base', 'field_instance')));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add new "Equipment used" field to logs.
|
||||
*/
|
||||
function farm_equipment_update_7004(&$sandbox) {
|
||||
|
||||
// Load field types.
|
||||
$field_types = field_info_fields();
|
||||
|
||||
// Create the equipment field base, if it doesn't already exist.
|
||||
if (empty($field_types['field_farm_equipment'])) {
|
||||
$field_base = array(
|
||||
'active' => 1,
|
||||
'cardinality' => -1,
|
||||
'deleted' => 0,
|
||||
'entity_types' => array(),
|
||||
'field_name' => 'field_farm_equipment',
|
||||
'indexes' => array(
|
||||
'target_id' => array(
|
||||
0 => 'target_id',
|
||||
),
|
||||
),
|
||||
'locked' => 0,
|
||||
'module' => 'entityreference',
|
||||
'settings' => array(
|
||||
'handler' => 'base',
|
||||
'handler_settings' => array(
|
||||
'behaviors' => array(
|
||||
'views-select-list' => array(
|
||||
'status' => 0,
|
||||
),
|
||||
),
|
||||
'sort' => array(
|
||||
'type' => 'none',
|
||||
),
|
||||
'target_bundles' => array(
|
||||
'equipment'
|
||||
),
|
||||
),
|
||||
'target_type' => 'farm_asset',
|
||||
),
|
||||
'translatable' => 0,
|
||||
'type' => 'entityreference',
|
||||
);
|
||||
field_create_field($field_base);
|
||||
}
|
||||
|
||||
// Load field instances.
|
||||
$field_instances = field_info_instances();
|
||||
|
||||
// Create new field instances on log types.
|
||||
$log_types = log_type_get_names();
|
||||
foreach ($log_types as $bundle => $bundle_info) {
|
||||
|
||||
// If the instance already exists, skip it.
|
||||
if (!empty($field_instances['log'][$bundle]['field_farm_equipment'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Create a field instance.
|
||||
$field_instance = array(
|
||||
'bundle' => $bundle,
|
||||
'deleted' => 0,
|
||||
'description' => 'What equipment was used?',
|
||||
'display' => array(
|
||||
'default' => array(
|
||||
'label' => 'inline',
|
||||
'module' => 'entityreference',
|
||||
'settings' => array(
|
||||
'bypass_access' => FALSE,
|
||||
'link' => 1,
|
||||
),
|
||||
'type' => 'entityreference_label',
|
||||
'weight' => 0,
|
||||
),
|
||||
),
|
||||
'entity_type' => 'log',
|
||||
'field_name' => 'field_farm_equipment',
|
||||
'label' => t('Equipment used'),
|
||||
'required' => 0,
|
||||
'settings' => array(
|
||||
'user_register_form' => FALSE,
|
||||
),
|
||||
'widget' => array(
|
||||
'active' => 1,
|
||||
'module' => 'entityreference_view_widget',
|
||||
'settings' => array(
|
||||
'allow_duplicates' => 0,
|
||||
'close_modal' => 1,
|
||||
'pass_argument' => 1,
|
||||
'pass_arguments' => '',
|
||||
'rendered_entity' => 0,
|
||||
'view' => 'farm_asset_entityreference_view|entityreference_view_widget',
|
||||
'view_mode' => 'full',
|
||||
),
|
||||
'type' => 'entityreference_view_widget',
|
||||
'weight' => 2,
|
||||
),
|
||||
);
|
||||
field_create_instance($field_instance);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue