3
0
Fork 0
mirror of https://github.com/farmOS/farmOS.git synced 2024-02-23 11:37:38 +01:00

Move log quantity base field definition to farm_log_quantity module.

The farm_inventory module had an implicit dependency on this
field, so by moving this out to its own module we can depend
on it explicitly without adding a dependency on farm_entity
as a whole.
This commit is contained in:
Michael Stenta 2021-07-20 14:20:04 -04:00
parent 119c996b0d
commit cdfe4dc5a4
7 changed files with 52 additions and 14 deletions

View file

@ -176,17 +176,6 @@ function farm_entity_log_base_fields() {
'view' => -70,
],
],
'quantity' => [
'type' => 'entity_reference_revisions',
'label' => t('Quantity'),
'description' => t('Add quantity measurements to this log.'),
'target_type' => 'quantity',
'multiple' => TRUE,
'weight' => [
'form' => 0,
'view' => 0,
],
],
];
$fields = [];
foreach ($field_info as $name => $info) {

View file

@ -21,6 +21,6 @@ dependencies:
- farm:farm_id_tag
- farm:farm_location
- farm:farm_log_category
- farm:quantity
- farm:farm_log_quantity
- log:log
- token:token

View file

@ -6,7 +6,6 @@ core_version_requirement: ^9
dependencies:
- drupal:field
- entity:entity
- entity_reference_revisions:entity_reference_revisions
- farm:farm_map
- fraction:fraction
- inline_entity_form:inline_entity_form

View file

@ -7,5 +7,6 @@ dependencies:
- drupal:options
- farm:asset
- farm:farm_field
- farm:farm_log_quantity
- farm:quantity
- fraction:fraction

View file

@ -33,10 +33,10 @@ class InventoryTest extends KernelTestBase {
'farm_field',
'farm_inventory',
'farm_inventory_test',
'farm_log_quantity',
'farm_quantity_standard',
'farm_unit',
'fraction',
'geofield',
'log',
'options',
'quantity',

View file

@ -0,0 +1,10 @@
name: farmOS Log Quantity
description: Adds a quantity reference field to logs.
type: module
package: farmOS
core_version_requirement: ^9
dependencies:
- entity_reference_revisions:entity_reference_revisions
- farm:farm_field
- farm:farm_log
- farm:quantity

View file

@ -0,0 +1,39 @@
<?php
/**
* @file
* Contains farm_log_quantity.module.
*/
use Drupal\Core\Entity\EntityTypeInterface;
/**
* Implements hook_entity_base_field_info().
*/
function farm_log_quantity_entity_base_field_info(EntityTypeInterface $entity_type) {
// We only care about log entities.
if ($entity_type->id() != 'log') {
return [];
}
// Add a quantity reference field to logs.
$field_info = [
'quantity' => [
'type' => 'entity_reference_revisions',
'label' => t('Quantity'),
'description' => t('Add quantity measurements to this log.'),
'target_type' => 'quantity',
'multiple' => TRUE,
'weight' => [
'form' => 0,
'view' => 0,
],
],
];
$fields = [];
foreach ($field_info as $name => $info) {
$fields[$name] = \Drupal::service('farm_field.factory')->baseFieldDefinition($info);
}
return $fields;
}