Move Log Owner base field to dedicated farm_owner module.

This commit is contained in:
Michael Stenta 2021-09-23 10:19:14 -04:00
parent 1f0c254e79
commit 0f84ff1575
5 changed files with 44 additions and 11 deletions

View File

@ -165,17 +165,6 @@ function farm_entity_log_base_fields() {
'view' => 0,
],
],
'owner' => [
'type' => 'entity_reference',
'label' => t('Assigned to'),
'description' => t('Optionally assign this task to one or more people.'),
'target_type' => 'user',
'multiple' => TRUE,
'weight' => [
'form' => -70,
'view' => -70,
],
],
];
$fields = [];
foreach ($field_info as $name => $info) {

View File

@ -22,5 +22,6 @@ dependencies:
- farm:farm_location
- farm:farm_log_category
- farm:farm_log_quantity
- farm:farm_owner
- log:log
- token:token

View File

@ -36,6 +36,7 @@ class FarmEntityFieldTest extends KernelTestBase {
'farm_entity_test',
'farm_location',
'farm_log',
'farm_owner',
];
/**

View File

@ -0,0 +1,9 @@
name: farmOS Owner
description: Provides an Owner field for farmOS records.
type: module
package: farmOS
core_version_requirement: ^9
dependencies:
- drupal:user
- farm:farm_field
- log:log

View File

@ -0,0 +1,33 @@
<?php
/**
* @file
* Contains farm_owner.module.
*/
use Drupal\Core\Entity\EntityTypeInterface;
/**
* Implements hook_entity_base_field_info().
*/
function farm_owner_entity_base_field_info(EntityTypeInterface $entity_type) {
$fields = [];
// Add owner field to logs.
if ($entity_type->id() == 'log') {
$field_info = [
'type' => 'entity_reference',
'label' => t('Assigned to'),
'description' => t('Optionally assign this task to one or more people.'),
'target_type' => 'user',
'multiple' => TRUE,
'weight' => [
'form' => -70,
'view' => -70,
],
];
$fields['owner'] = \Drupal::service('farm_field.factory')->baseFieldDefinition($field_info);
}
return $fields;
}