Move transplant_days field to farm_transplant module #795

This commit is contained in:
Michael Stenta 2024-02-08 14:44:15 -05:00
parent 8645a4428f
commit dc94c89353
8 changed files with 34 additions and 21 deletions

View File

@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- [Set the minimum value of maturity_days and transplant_days to 1 #794](https://github.com/farmOS/farmOS/pull/794)
- [Move transplant_days field to farm_transplant module #795](https://github.com/farmOS/farmOS/pull/795)
### Fixed

View File

@ -87,7 +87,7 @@ above, some types add additional type-specific fields. These include:
Terms in the "Plant type" vocabulary have the following additional attributes:
- Days to maturity (Integer)
- Days to transplant (Integer)
- Days to transplant (Integer) (Added by the optional Transplanting module)
- Days of harvest (Integer)
And the following additional relationships:

View File

@ -6,7 +6,7 @@ dependencies:
- taxonomy.vocabulary.plant_type
enforced:
module:
- farm_plant_type
- farm_transplanting
id: taxonomy_term.plant_type.transplant_days
field_name: transplant_days
entity_type: taxonomy_term

View File

@ -3,7 +3,7 @@ status: true
dependencies:
enforced:
module:
- farm_plant_type
- farm_transplanting
module:
- taxonomy
id: taxonomy_term.transplant_days

View File

@ -6,4 +6,5 @@ core_version_requirement: ^10
dependencies:
- farm:farm_entity
- farm:farm_plant
- farm:farm_plant_type
- log:log

View File

@ -7,7 +7,6 @@ dependencies:
- field.field.taxonomy_term.plant_type.harvest_days
- field.field.taxonomy_term.plant_type.image
- field.field.taxonomy_term.plant_type.maturity_days
- field.field.taxonomy_term.plant_type.transplant_days
- image.style.thumbnail
- taxonomy.vocabulary.plant_type
module:
@ -86,11 +85,4 @@ content:
settings:
display_label: true
third_party_settings: { }
transplant_days:
type: number
weight: 3
region: content
settings:
placeholder: ''
third_party_settings: { }
hidden: { }

View File

@ -7,7 +7,6 @@ dependencies:
- field.field.taxonomy_term.plant_type.harvest_days
- field.field.taxonomy_term.plant_type.image
- field.field.taxonomy_term.plant_type.maturity_days
- field.field.taxonomy_term.plant_type.transplant_days
- taxonomy.vocabulary.plant_type
module:
- image
@ -72,13 +71,4 @@ content:
third_party_settings: { }
weight: 3
region: content
transplant_days:
type: number_integer
label: above
settings:
thousand_separator: ''
prefix_suffix: true
third_party_settings: { }
weight: 2
region: content
hidden: { }

View File

@ -99,3 +99,32 @@ function farm_plant_type_post_update_add_harvest_days(&$sandbox) {
]);
$field->save();
}
/**
* Move transplant_days field to farm_transplant module.
*/
function farm_plan_type_post_update_move_transplant_days() {
// The transplant_days field was previously part of this module. It has moved
// to the farm_transplanting module, so that it is only made available in
// instances that deal with transplants. If the farm_transplant module is not
// installed, and there is no data in the taxonomy_term__transplant_days
// table, then this will uninstall the field to remove the unnecessary table.
if (\Drupal::service('module_handler')->moduleExists('farm_transplanting')) {
return;
}
$data_count = \Drupal::database()->query('SELECT COUNT(*) FROM {taxonomy_term__transplant_days}')->fetchField();
if (!empty($data_count)) {
return;
}
// Delete the transplant_days field.
$field = FieldConfig::load('taxonomy_term.plant_type.transplant_days');
if (!empty($field)) {
$field->delete();
}
$field_storage = FieldStorageConfig::load('taxonomy_term.transplant_days');
if (!empty($field_storage)) {
$field_storage->delete();
}
}