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

Move Geometry field definition to location module.

This commit is contained in:
Michael Stenta 2020-10-13 22:50:28 -04:00
parent c95443e989
commit f9fff6f3b7
5 changed files with 42 additions and 28 deletions

View file

@ -18,6 +18,7 @@ dependencies:
- farm:farm_flag
- farm:farm_format
- farm:farm_id_tag
- farm:farm_location
- farm:farm_log_category
- log:log
- token:token

View file

@ -11,28 +11,4 @@ class FarmLogType extends LogTypeBase {
use StringTranslationTrait;
/**
* {@inheritdoc}
*/
public function buildFieldDefinitions() {
$fields = [];
// Geometry field.
// This is added as a bundle field definition to all log types rather than
// a base field definition so that data is stored in a dedicated database
// table.
$options = [
'type' => 'geofield',
'label' => $this->t('Geometry'),
'description' => $this->t('Add geometry data to this log to describe where it took place.'),
'weight' => [
'form' => 95,
'view' => 95,
],
];
$fields['geometry'] = \Drupal::service('farm_field.factory')->bundleFieldDefinition($options);
return $fields;
}
}

View file

@ -34,6 +34,7 @@ class FarmEntityFieldTest extends KernelTestBase {
'farm_field',
'farm_entity',
'farm_entity_test',
'farm_location',
];
/**
@ -66,6 +67,7 @@ class FarmEntityFieldTest extends KernelTestBase {
$this->assertArrayHasKey('data', $fields);
$this->assertArrayHasKey('flag', $fields);
$this->assertArrayHasKey('file', $fields);
$this->assertArrayHasKey('geometry', $fields);
$this->assertArrayHasKey('image', $fields);
$this->assertArrayHasKey('notes', $fields);
$this->assertArrayHasKey('owner', $fields);
@ -111,10 +113,6 @@ class FarmEntityFieldTest extends KernelTestBase {
*/
public function testBuildFieldDefinitions() {
// Test log field definitions.
$fields = $this->entityFieldManager->getFieldDefinitions('log', 'test');
$this->assertArrayHasKey('geometry', $fields);
// Test plan field definitions.
$fields = $this->entityFieldManager->getFieldDefinitions('plan', 'test');
$this->assertArrayHasKey('asset', $fields);

View file

@ -3,3 +3,6 @@ description: Provides movement/location tracking for assets via logs.
type: module
package: farmOS
core_version_requirement: ^9
dependencies:
- farm:farm_field
- geofield:geofield

View file

@ -0,0 +1,36 @@
<?php
/**
* @file
* Contains farm_location.module.
*/
use Drupal\Core\Entity\EntityTypeInterface;
/**
* Implements hook_entity_base_field_info().
*/
function farm_location_entity_base_field_info(EntityTypeInterface $entity_type) {
$fields = [];
// Add fields to logs.
if ($entity_type->id() == 'log') {
// Geometry field.
// This is added as a bundle field definition to all log types rather than
// a base field definition so that data is stored in a dedicated database
// table.
$options = [
'type' => 'geofield',
'label' => t('Geometry'),
'description' => t('Add geometry data to this log to describe where it took place.'),
'weight' => [
'form' => 95,
'view' => 95,
],
];
$fields['geometry'] = \Drupal::service('farm_field.factory')->bundleFieldDefinition($options);
}
return $fields;
}