Move "Equipment used" field to its own module: farm_equipment_field.
This commit is contained in:
parent
e561c22497
commit
d5324e9222
10
farm.install
10
farm.install
|
@ -21,6 +21,7 @@ function farm_modules() {
|
|||
'farm_crop' => st('Crops'),
|
||||
'farm_livestock' => st('Livestock'),
|
||||
'farm_equipment' => st('Equipment'),
|
||||
'farm_equipment_field' => st('Add "Equipment used" field to logs'),
|
||||
'farm_calendar' => st('Calendar of logs'),
|
||||
'farm_import' => st('CSV importers for assets and logs'),
|
||||
'farm_quick' => st('Quick forms UI'),
|
||||
|
@ -801,6 +802,15 @@ function farm_update_7047(&$sandbox) {
|
|||
_farm_update_enable_modules(array('farm_data_field'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add "Equipment used" field to logs (if Equipment module is enabled).
|
||||
*/
|
||||
function farm_update_7048(&$sandbox) {
|
||||
if (module_exists('farm_equipment')) {
|
||||
_farm_update_enable_modules(array('farm_equipment_field'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update helper function: enable modules.
|
||||
*/
|
||||
|
|
|
@ -10,41 +10,6 @@
|
|||
function farm_equipment_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',
|
||||
);
|
||||
|
||||
// Exported field_base: 'field_farm_manufacturer'.
|
||||
$field_bases['field_farm_manufacturer'] = array(
|
||||
'active' => 1,
|
||||
|
|
|
@ -716,51 +716,5 @@ function farm_equipment_field_default_field_instances() {
|
|||
t('What areas did this maintenance take place in?');
|
||||
t('What assets do this maintenance log pertain to?');
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
|
|
@ -418,73 +418,3 @@ function farm_equipment_field_group_info() {
|
|||
|
||||
return $field_groups;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_group_info_alter().
|
||||
*/
|
||||
function farm_equipment_field_group_info_alter(&$groups) {
|
||||
|
||||
// Iterate through the groups and make a list of asset and general groups.
|
||||
$asset_groups = array();
|
||||
$general_groups = array();
|
||||
foreach ($groups as $key => $group) {
|
||||
|
||||
// If we don't know the entity type, bail.
|
||||
if (empty($group->entity_type)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Only alter logs.
|
||||
if ($group->entity_type != 'log') {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Only alter the form.
|
||||
if ($group->mode != 'form') {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Add it to one of the listed based on its name.
|
||||
switch ($group->group_name) {
|
||||
case 'group_farm_assets':
|
||||
$asset_groups[] = $key;
|
||||
break;
|
||||
case 'group_farm_general':
|
||||
$general_groups[] = $key;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove general groups on log types that have an assets group.
|
||||
foreach ($asset_groups as $key) {
|
||||
|
||||
// Get the asset group from the original groups array.
|
||||
$asset_group = $groups[$key];
|
||||
|
||||
// Assemble the identifier for this bundle's general group.
|
||||
$parts = array(
|
||||
'group_farm_general',
|
||||
$asset_group->entity_type,
|
||||
$asset_group->bundle,
|
||||
$asset_group->mode,
|
||||
);
|
||||
$general_group_key = implode('|', $parts);
|
||||
|
||||
// Remove the general group.
|
||||
$key = array_search($general_group_key, $general_groups);
|
||||
if ($key !== FALSE) {
|
||||
unset($general_groups[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
// Merge the asset and general groups into a final list of groups we want to
|
||||
// add the equipment field to.
|
||||
$alter_groups = array_merge($asset_groups, $general_groups);
|
||||
|
||||
// Iterate through the groups we want to alter.
|
||||
foreach ($alter_groups as $key) {
|
||||
|
||||
// Add the "Equipment used" field.
|
||||
$groups[$key]->data['children'][] = "field_farm_equipment";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,7 +42,6 @@ features[ctools][] = strongarm:strongarm:1
|
|||
features[ctools][] = views:views_default:3.0
|
||||
features[farm_asset_type][] = equipment
|
||||
features[features_api][] = api:2
|
||||
features[field_base][] = field_farm_equipment
|
||||
features[field_base][] = field_farm_manufacturer
|
||||
features[field_base][] = field_farm_model
|
||||
features[field_base][] = field_farm_serial_number
|
||||
|
|
|
@ -67,105 +67,3 @@ 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,0 +1,50 @@
|
|||
<?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;
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
<?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;
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* farm_equipment_field.features.inc
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_ctools_plugin_api().
|
||||
*/
|
||||
function farm_equipment_field_ctools_plugin_api($module = NULL, $api = NULL) {
|
||||
if ($module == "field_group" && $api == "field_group") {
|
||||
return array("version" => "1");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
/**
|
||||
* @file
|
||||
* farm_equipment_field.field_group.inc
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_field_group_info_alter().
|
||||
*/
|
||||
function farm_equipment_field_field_group_info_alter(&$groups) {
|
||||
|
||||
// Iterate through the groups and make a list of asset and general groups.
|
||||
$asset_groups = array();
|
||||
$general_groups = array();
|
||||
foreach ($groups as $key => $group) {
|
||||
|
||||
// If we don't know the entity type, bail.
|
||||
if (empty($group->entity_type)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Only alter logs.
|
||||
if ($group->entity_type != 'log') {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Only alter the form.
|
||||
if ($group->mode != 'form') {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Add it to one of the listed based on its name.
|
||||
switch ($group->group_name) {
|
||||
case 'group_farm_assets':
|
||||
$asset_groups[] = $key;
|
||||
break;
|
||||
case 'group_farm_general':
|
||||
$general_groups[] = $key;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove general groups on log types that have an assets group.
|
||||
foreach ($asset_groups as $key) {
|
||||
|
||||
// Get the asset group from the original groups array.
|
||||
$asset_group = $groups[$key];
|
||||
|
||||
// Assemble the identifier for this bundle's general group.
|
||||
$parts = array(
|
||||
'group_farm_general',
|
||||
$asset_group->entity_type,
|
||||
$asset_group->bundle,
|
||||
$asset_group->mode,
|
||||
);
|
||||
$general_group_key = implode('|', $parts);
|
||||
|
||||
// Remove the general group.
|
||||
$key = array_search($general_group_key, $general_groups);
|
||||
if ($key !== FALSE) {
|
||||
unset($general_groups[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
// Merge the asset and general groups into a final list of groups we want to
|
||||
// add the equipment field to.
|
||||
$alter_groups = array_merge($asset_groups, $general_groups);
|
||||
|
||||
// Iterate through the groups we want to alter.
|
||||
foreach ($alter_groups as $key) {
|
||||
|
||||
// Add the "Equipment used" field.
|
||||
$groups[$key]->data['children'][] = "field_farm_equipment";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
name = Farm Equipment Field
|
||||
description = Adds an "Equipment used" field to logs.
|
||||
core = 7.x
|
||||
package = farmOS
|
||||
dependencies[] = ctools
|
||||
dependencies[] = entity
|
||||
dependencies[] = entityreference
|
||||
dependencies[] = entityreference_view_widget
|
||||
dependencies[] = farm_asset
|
||||
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
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Farm equipment field module.
|
||||
*/
|
||||
|
||||
include_once 'farm_equipment_field.features.inc';
|
Loading…
Reference in New Issue