Add Birth log type and migration.

This commit is contained in:
Michael Stenta 2021-05-26 11:02:44 -04:00
parent 85bb0fcb4a
commit 360e133164
5 changed files with 114 additions and 0 deletions

View File

@ -50,6 +50,7 @@ function farm_modules() {
'farm_group' => t('Group assets'),
'farm_transplanting' => t('Transplanting logs'),
'farm_lab_test' => t('Lab test logs'),
'farm_birth' => t('Birth logs'),
'farm_medical' => t('Medical logs'),
'farm_purchase' => t('Purchase logs'),
'farm_sale' => t('Sale logs'),

View File

@ -0,0 +1,42 @@
langcode: en
status: true
dependencies:
enforced:
module:
- farm_birth
- farm_migrate
id: farm_migrate_log_birth
label: 'Logs (Birth)'
migration_group: farm_migrate_log
migration_tags:
- 'Drupal 7'
- 'farmOS 1.x'
class: Drupal\migrate\Plugin\Migration
field_plugin_method: null
cck_plugin_method: null
source:
plugin: d7_farm_log
bundle: farm_birth
destination:
plugin: 'entity:log'
process:
# Hard-code the bundle.
type:
plugin: default_value
default_value: birth
# Maintain the log ID.
id:
plugin: get
source: id
# Birth specific fields.
mother:
plugin: sub_process
source: field_farm_mother
process:
target_id:
plugin: farm_migration_group_lookup
migration_group: farm_migrate_asset
source: target_id
migration_dependencies:
required: { }
optional: { }

View File

@ -0,0 +1,12 @@
langcode: en
status: true
dependencies:
enforced:
module:
- farm_birth
id: birth
label: Birth
description: ''
name_pattern: 'Birth log [log:id]'
workflow: log_default
new_revision: true

View File

@ -0,0 +1,8 @@
name: Birth log
description: Adds a Birth log type for Animal assets.
type: module
package: farmOS Logs
core_version_requirement: ^9
dependencies:
- farm:farm_animal
- farm:farm_entity

View File

@ -0,0 +1,51 @@
<?php
namespace Drupal\farm_birth\Plugin\Log\LogType;
use Drupal\farm_entity\Plugin\Log\LogType\FarmLogType;
/**
* Provides the birth log type.
*
* @LogType(
* id = "birth",
* label = @Translation("Birth"),
* )
*/
class Birth extends FarmLogType {
/**
* {@inheritdoc}
*/
public function buildFieldDefinitions() {
$fields = parent::buildFieldDefinitions();
// Mother.
$options = [
'type' => 'entity_reference',
'label' => $this->t('Mother'),
'target_type' => 'asset',
'target_bundle' => 'animal',
'weight' => [
'form' => 55,
'view' => -5,
],
];
$fields['mother'] = $this->farmFieldFactory->bundleFieldDefinition($options);
// Veterinarian.
$options = [
'type' => 'string',
'label' => $this->t('Veterinarian'),
'description' => $this->t('If a veterinarian was involved, enter their name here.'),
'weight' => [
'form' => -40,
'view' => -40,
],
];
$fields['vet'] = $this->farmFieldFactory->bundleFieldDefinition($options);
return $fields;
}
}