3
0
Fork 0
mirror of https://github.com/farmOS/farmOS.git synced 2024-02-23 11:37:38 +01:00

Refactor farm_equipment_field to use farm_dynamic_fields.

This commit is contained in:
Michael Stenta 2019-04-10 15:21:06 -04:00
parent d5324e9222
commit 611de73ee0
4 changed files with 100 additions and 111 deletions

View file

@ -1,50 +0,0 @@
<?php
/**
* @file
* farm_equipment_field.features.field_base.inc
*/
/**
* Implements hook_field_default_field_bases().
*/
function farm_equipment_field_field_default_field_bases() {
$field_bases = array();
// Exported field_base: 'field_farm_equipment'.
$field_bases['field_farm_equipment'] = 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(
0 => 'equipment',
),
),
'target_type' => 'farm_asset',
),
'translatable' => 0,
'type' => 'entityreference',
);
return $field_bases;
}

View file

@ -1,60 +0,0 @@
<?php
/**
* @file
* farm_equipment_field.features.field_instance.inc
*/
/**
* Implements hook_field_default_field_instances().
*/
function farm_equipment_field_field_default_field_instances() {
$field_instances = array();
// Get a list of log types.
$log_types = log_types();
// Iterate through the log types and add an equipment reference field to each.
foreach ($log_types as $bundle => $info) {
$field_instances['log-' . $bundle . '-field_farm_equipment'] = 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,
),
);
}
return $field_instances;
}

View file

@ -7,9 +7,9 @@ dependencies[] = entity
dependencies[] = entityreference
dependencies[] = entityreference_view_widget
dependencies[] = farm_asset
dependencies[] = farm_fields_dynamic
dependencies[] = features
dependencies[] = field_group
dependencies[] = log
features[ctools][] = field_group:field_group:1
features[features_api][] = api:2
features[field_base][] = field_farm_equipment

View file

@ -6,3 +6,102 @@
*/
include_once 'farm_equipment_field.features.inc';
/**
* Implements hook_farm_fields_dynamic_bases().
*/
function farm_equipment_farm_fields_dynamic_bases() {
return array(
'field_farm_equipment' => 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(
0 => 'equipment',
),
),
'target_type' => 'farm_asset',
),
'translatable' => 0,
'type' => 'entityreference',
),
);
}
/**
* Implements hook_farm_fields_dynamic_instances().
*/
function farm_equipment_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();
// Iterate through the log types and add an equipment reference field to each.
foreach ($log_types as $bundle => $info) {
$field_instances['log-' . $bundle . '-field_farm_equipment'] = 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,
),
);
}
// Return the array of field instance definitions.
return $field_instances;
}