Skip to content

Commit

Permalink
Add "equipment used" field to logs on existing sites.
Browse files Browse the repository at this point in the history
  • Loading branch information
mstenta committed Apr 11, 2019
1 parent e33e152 commit edb67fb
Showing 1 changed file with 102 additions and 0 deletions.
102 changes: 102 additions & 0 deletions modules/farm/farm_equipment/farm_equipment.install
Expand Up @@ -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);
}
}

0 comments on commit edb67fb

Please sign in to comment.