From a02ebcfae0993df3146f42583dbfa95c1fb88a92 Mon Sep 17 00:00:00 2001 From: Michael Stenta Date: Wed, 20 Mar 2024 10:03:46 -0400 Subject: [PATCH 1/2] Install farm_plant_type config in Planting quick form kernel test. --- modules/quick/planting/tests/src/Kernel/QuickPlantingTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/quick/planting/tests/src/Kernel/QuickPlantingTest.php b/modules/quick/planting/tests/src/Kernel/QuickPlantingTest.php index 76213c5b0b..6590cf0c3b 100644 --- a/modules/quick/planting/tests/src/Kernel/QuickPlantingTest.php +++ b/modules/quick/planting/tests/src/Kernel/QuickPlantingTest.php @@ -24,6 +24,7 @@ class QuickPlantingTest extends QuickFormTestBase { * {@inheritdoc} */ protected static $modules = [ + 'entity_reference_validators', 'farm_harvest', 'farm_land', 'farm_plant', @@ -34,6 +35,7 @@ class QuickPlantingTest extends QuickFormTestBase { 'farm_seeding', 'farm_transplanting', 'farm_unit', + 'field', ]; /** @@ -45,6 +47,7 @@ protected function setUp(): void { 'farm_harvest', 'farm_land', 'farm_plant', + 'farm_plant_type', 'farm_quantity_standard', 'farm_seeding', 'farm_transplanting', From ee183af113691f8d256bb6e0358e026d281cd7a4 Mon Sep 17 00:00:00 2001 From: Michael Stenta Date: Thu, 8 Feb 2024 14:44:15 -0500 Subject: [PATCH 2/2] Move transplant_days field to farm_transplant module #795 --- CHANGELOG.md | 1 + docs/model/type/term.md | 2 +- ...xonomy_term.plant_type.transplant_days.yml | 2 +- ....storage.taxonomy_term.transplant_days.yml | 2 +- .../transplanting/farm_transplanting.info.yml | 1 + .../transplanting/farm_transplanting.module | 43 +++++++++++++++++++ .../plant_type/farm_plant_type.module | 18 -------- .../farm_plant_type.post_update.php | 34 +++++++++++++++ 8 files changed, 82 insertions(+), 21 deletions(-) rename modules/{taxonomy/plant_type => log/transplanting}/config/install/field.field.taxonomy_term.plant_type.transplant_days.yml (94%) rename modules/{taxonomy/plant_type => log/transplanting}/config/install/field.storage.taxonomy_term.transplant_days.yml (93%) create mode 100644 modules/log/transplanting/farm_transplanting.module diff --git a/CHANGELOG.md b/CHANGELOG.md index 5780005ce0..5df7121f37 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [Do not trim whitespace from quantity field item content #820](https://github.com/farmOS/farmOS/pull/820) - [Do not install base modules when --existing-config is used #821](https://github.com/farmOS/farmOS/pull/821) - [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) ## [3.1.2] 2024-02-26 diff --git a/docs/model/type/term.md b/docs/model/type/term.md index eb0f74125e..d232ed48ad 100644 --- a/docs/model/type/term.md +++ b/docs/model/type/term.md @@ -104,7 +104,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: diff --git a/modules/taxonomy/plant_type/config/install/field.field.taxonomy_term.plant_type.transplant_days.yml b/modules/log/transplanting/config/install/field.field.taxonomy_term.plant_type.transplant_days.yml similarity index 94% rename from modules/taxonomy/plant_type/config/install/field.field.taxonomy_term.plant_type.transplant_days.yml rename to modules/log/transplanting/config/install/field.field.taxonomy_term.plant_type.transplant_days.yml index 672483ec09..d0a6b6c370 100644 --- a/modules/taxonomy/plant_type/config/install/field.field.taxonomy_term.plant_type.transplant_days.yml +++ b/modules/log/transplanting/config/install/field.field.taxonomy_term.plant_type.transplant_days.yml @@ -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 diff --git a/modules/taxonomy/plant_type/config/install/field.storage.taxonomy_term.transplant_days.yml b/modules/log/transplanting/config/install/field.storage.taxonomy_term.transplant_days.yml similarity index 93% rename from modules/taxonomy/plant_type/config/install/field.storage.taxonomy_term.transplant_days.yml rename to modules/log/transplanting/config/install/field.storage.taxonomy_term.transplant_days.yml index ff0b123150..d7ee8669e5 100644 --- a/modules/taxonomy/plant_type/config/install/field.storage.taxonomy_term.transplant_days.yml +++ b/modules/log/transplanting/config/install/field.storage.taxonomy_term.transplant_days.yml @@ -3,7 +3,7 @@ status: true dependencies: enforced: module: - - farm_plant_type + - farm_transplanting module: - taxonomy id: taxonomy_term.transplant_days diff --git a/modules/log/transplanting/farm_transplanting.info.yml b/modules/log/transplanting/farm_transplanting.info.yml index a2ef05efad..b0e55a5eaa 100644 --- a/modules/log/transplanting/farm_transplanting.info.yml +++ b/modules/log/transplanting/farm_transplanting.info.yml @@ -6,4 +6,5 @@ core_version_requirement: ^10 dependencies: - farm:farm_entity - farm:farm_plant + - farm:farm_plant_type - log:log diff --git a/modules/log/transplanting/farm_transplanting.module b/modules/log/transplanting/farm_transplanting.module new file mode 100644 index 0000000000..006c43d438 --- /dev/null +++ b/modules/log/transplanting/farm_transplanting.module @@ -0,0 +1,43 @@ +getMode() == 'default' && $form_display->isNew()) { + $form_display->setComponent('transplant_days', [ + 'type' => 'number', + 'settings' => [ + 'placeholder' => '', + ], + 'region' => 'content', + 'weight' => 15, + ]); + } +} + +/** + * Implements hook_entity_view_display_alter(). + */ +function farm_transplanting_entity_view_display_alter(EntityViewDisplayInterface $display, array $context) { + if ($context['entity_type'] == 'taxonomy_term' && $context['bundle'] == 'plant_type' && $display->getMode() == 'full' && $display->isNew()) { + $display->setComponent('transplant_days', [ + 'type' => 'number_integer', + 'label' => 'inline', + 'settings' => [ + 'thousand_separator' => '', + 'prefix_suffix' => TRUE, + ], + 'region' => 'content', + 'weight' => 15, + ]); + } +} diff --git a/modules/taxonomy/plant_type/farm_plant_type.module b/modules/taxonomy/plant_type/farm_plant_type.module index 562fb490b4..6ee5065945 100644 --- a/modules/taxonomy/plant_type/farm_plant_type.module +++ b/modules/taxonomy/plant_type/farm_plant_type.module @@ -32,14 +32,6 @@ function farm_plant_type_entity_form_display_alter(EntityFormDisplayInterface $f 'region' => 'content', 'weight' => 20, ]); - $form_display->setComponent('transplant_days', [ - 'type' => 'number', - 'settings' => [ - 'placeholder' => '', - ], - 'region' => 'content', - 'weight' => 15, - ]); $form_display->setComponent('harvest_days', [ 'type' => 'number', 'settings' => [ @@ -86,16 +78,6 @@ function farm_plant_type_entity_view_display_alter(EntityViewDisplayInterface $d 'region' => 'content', 'weight' => 20, ]); - $display->setComponent('transplant_days', [ - 'type' => 'number_integer', - 'label' => 'inline', - 'settings' => [ - 'thousand_separator' => '', - 'prefix_suffix' => TRUE, - ], - 'region' => 'content', - 'weight' => 15, - ]); $display->setComponent('harvest_days', [ 'type' => 'number_integer', 'label' => 'inline', diff --git a/modules/taxonomy/plant_type/farm_plant_type.post_update.php b/modules/taxonomy/plant_type/farm_plant_type.post_update.php index bd8fc3b172..7cce920d9d 100644 --- a/modules/taxonomy/plant_type/farm_plant_type.post_update.php +++ b/modules/taxonomy/plant_type/farm_plant_type.post_update.php @@ -115,3 +115,37 @@ function farm_plant_type_post_update_add_harvest_days(&$sandbox) { ]); $field->save(); } + +/** + * Move transplant_days field to farm_transplant module. + */ +function farm_plant_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 there is transplant_days data in + // the database, but the farm_transplant module is not installed, we should + // install it so that module can be responsible for the data moving forward. + $data_count = \Drupal::database()->query('SELECT COUNT(*) FROM {taxonomy_term__transplant_days}')->fetchField(); + if (!empty($data_count)) { + if (!\Drupal::service('module_handler')->moduleExists('farm_transplanting')) { + \Drupal::configFactory()->getEditable('field.field.taxonomy_term.plant_type.transplant_days')->delete(); + \Drupal::configFactory()->getEditable('field.storage.taxonomy_term.transplant_days')->delete(); + \Drupal::service('module_installer')->install(['farm_transplanting']); + } + } + + // Otherwise, we can delete the transplant_days field. + // Using FieldConfig::load() and FieldStorageConfig::load() and their + // associated delete() methods will delete the config and database tables. + else { + $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(); + } + } +}