This commit is contained in:
Michael Stenta 2024-02-21 14:57:24 +00:00 committed by GitHub
commit 893d7606aa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 219 additions and 41 deletions

View File

@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Added
- [Add "Days of harvest" field to Plant type terms #794](https://github.com/farmOS/farmOS/pull/794)
### Changed
- [Set the minimum value of maturity_days and transplant_days to 1 #794](https://github.com/farmOS/farmOS/pull/794)
### Fixed
- [Check for correct update operation access in location hierarchy form #800](https://github.com/farmOS/farmOS/pull/800)

View File

@ -88,6 +88,7 @@ Terms in the "Plant type" vocabulary have the following additional attributes:
- Days to maturity (Integer)
- Days to transplant (Integer)
- Days of harvest (Integer)
And the following additional relationships:

View File

@ -4,17 +4,18 @@ dependencies:
config:
- field.field.taxonomy_term.plant_type.companions
- field.field.taxonomy_term.plant_type.crop_family
- 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
enforced:
module:
- farm_plant_type
module:
- image
- text
enforced:
module:
- farm_plant_type
id: taxonomy_term.plant_type.default
targetEntityType: taxonomy_term
bundle: plant_type
@ -22,7 +23,7 @@ mode: default
content:
companions:
type: entity_reference_autocomplete
weight: 5
weight: 6
region: content
settings:
match_operator: CONTAINS
@ -45,12 +46,19 @@ content:
weight: 1
region: content
settings:
placeholder: ''
rows: 5
placeholder: ''
third_party_settings: { }
harvest_days:
type: number
weight: 5
region: content
settings:
placeholder: ''
third_party_settings: { }
image:
type: image_image
weight: 6
weight: 7
region: content
settings:
progress_indicator: throbber
@ -73,10 +81,10 @@ content:
third_party_settings: { }
status:
type: boolean_checkbox
weight: 8
region: content
settings:
display_label: true
weight: 7
region: content
third_party_settings: { }
transplant_days:
type: number

View File

@ -4,16 +4,17 @@ dependencies:
config:
- field.field.taxonomy_term.plant_type.companions
- field.field.taxonomy_term.plant_type.crop_family
- 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
enforced:
module:
- farm_plant_type
module:
- image
- text
enforced:
module:
- farm_plant_type
id: taxonomy_term.plant_type.default
targetEntityType: taxonomy_term
bundle: plant_type
@ -21,52 +22,63 @@ mode: default
content:
companions:
type: entity_reference_label
weight: 4
region: content
label: above
settings:
link: true
third_party_settings: { }
crop_family:
type: entity_reference_label
weight: 1
region: content
label: above
settings:
link: true
third_party_settings: { }
description:
label: hidden
type: text_default
weight: 0
region: content
settings: { }
third_party_settings: { }
image:
type: image
weight: 5
region: content
crop_family:
type: entity_reference_label
label: above
settings:
image_style: ''
image_link: ''
link: true
third_party_settings: { }
weight: 1
region: content
description:
type: text_default
label: hidden
settings: { }
third_party_settings: { }
weight: 0
region: content
harvest_days:
type: number_integer
label: above
settings:
thousand_separator: ''
prefix_suffix: true
third_party_settings: { }
weight: 4
region: content
image:
type: image
label: above
settings:
image_link: ''
image_style: ''
image_loading:
attribute: lazy
third_party_settings: { }
weight: 6
region: content
maturity_days:
type: number_integer
label: above
settings:
thousand_separator: ''
prefix_suffix: true
third_party_settings: { }
weight: 3
region: content
label: above
settings:
thousand_separator: ''
prefix_suffix: true
third_party_settings: { }
transplant_days:
type: number_integer
weight: 2
region: content
label: above
settings:
thousand_separator: ''
prefix_suffix: true
third_party_settings: { }
weight: 2
region: content
hidden: { }

View File

@ -0,0 +1,25 @@
langcode: en
status: true
dependencies:
config:
- field.storage.taxonomy_term.harvest_days
- taxonomy.vocabulary.plant_type
enforced:
module:
- farm_plant_type
id: taxonomy_term.plant_type.harvest_days
field_name: harvest_days
entity_type: taxonomy_term
bundle: plant_type
label: 'Days of harvest'
description: ''
required: false
translatable: false
default_value: { }
default_value_callback: ''
settings:
min: 1
max: null
prefix: ''
suffix: ' day| days'
field_type: integer

View File

@ -18,7 +18,7 @@ translatable: false
default_value: { }
default_value_callback: ''
settings:
min: null
min: 1
max: null
prefix: ''
suffix: ' day| days'

View File

@ -18,7 +18,7 @@ translatable: false
default_value: { }
default_value_callback: ''
settings:
min: null
min: 1
max: null
prefix: ''
suffix: ' day| days'

View File

@ -0,0 +1,22 @@
langcode: en
status: true
dependencies:
enforced:
module:
- farm_plant_type
module:
- taxonomy
id: taxonomy_term.harvest_days
field_name: harvest_days
entity_type: taxonomy_term
type: integer
settings:
unsigned: true
size: normal
module: core
locked: false
cardinality: 1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false

View File

@ -4,4 +4,5 @@ type: module
package: farmOS Taxonomies
core_version_requirement: ^10
dependencies:
- drupal:image
- drupal:taxonomy

View File

@ -0,0 +1,101 @@
<?php
/**
* @file
* Post update hooks for the farm_plant_type module.
*/
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
/**
* Set the minimum value of maturity_days and transplant_days to 1.
*/
function farm_plant_type_post_update_min_1_day(&$sandbox) {
// Set the min setting of both fields to 1.
$field_names = [
'maturity_days',
'transplant_days',
];
foreach ($field_names as $field_name) {
$field = FieldConfig::load('taxonomy_term.plant_type.' . $field_name);
if (!empty($field)) {
$field->setSetting('min', 1);
$field->save();
}
}
// Delete any zero values from the database.
$tables = [
'taxonomy_term__maturity_days' => 'maturity_days_value',
'taxonomy_term__transplant_days' => 'transplant_days_value',
'taxonomy_term_revision__maturity_days' => 'maturity_days_value',
'taxonomy_term_revision__transplant_days' => 'transplant_days_value',
];
foreach ($tables as $table => $column) {
\Drupal::database()
->query('DELETE FROM {' . $table . '} WHERE ' . $column . ' = 0');
}
}
/**
* Add harvest_days field to plant_type terms.
*/
function farm_plant_type_post_update_add_harvest_days(&$sandbox) {
$field_storage = FieldStorageConfig::create([
'id' => 'taxonomy_term.harvest_days',
'field_name' => 'harvest_days',
'entity_type' => 'taxonomy_term',
'type' => 'integer',
'settings' => [
'unsigned' => TRUE,
'size' => 'normal',
],
'module' => 'core',
'locked' => FALSE,
'cardinality' => 1,
'indexes' => [],
'persist_with_no_fields' => FALSE,
'custom_storage' => FALSE,
'dependencies' => [
'enforced' => [
'module' => [
'farm_plant_type',
],
],
'module' => [
'taxonomy',
],
],
]);
$field_storage->save();
$field = FieldConfig::create([
'id' => 'taxonomy_term.plant_type.harvest_days',
'field_name' => 'harvest_days',
'entity_type' => 'taxonomy_term',
'bundle' => 'plant_type',
'label' => 'Days of harvest',
'description' => '',
'required' => FALSE,
'default_value' => [],
'default_value_callback' => '',
'settings' => [
'min' => 1,
'max' => NULL,
'prefix' => '',
'suffix' => ' day| days',
],
'field_type' => 'integer',
'dependencies' => [
'enforced' => [
'module' => [
'farm_plant_type',
],
],
'module' => [
'taxonomy',
],
],
]);
$field->save();
}