mirror of
https://github.com/farmOS/farmOS.git
synced 2024-02-23 11:37:38 +01:00
Add standard base fields to Plan entities: Data, Files, Images, Notes, Flags.
This commit is contained in:
parent
6e4e97ef5f
commit
26ab4ed331
|
@ -110,6 +110,39 @@ function farm_field_log_base_fields() {
|
|||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define common plan base fields.
|
||||
*/
|
||||
function farm_field_plan_base_fields() {
|
||||
$field_info = [
|
||||
'data' => [
|
||||
'type' => 'string_long',
|
||||
'label' => t('Data'),
|
||||
],
|
||||
'file' => [
|
||||
'type' => 'file',
|
||||
'label' => t('Files'),
|
||||
'file_directory' => 'farm/plan/[date:custom:Y]-[date:custom:m]',
|
||||
'multiple' => TRUE,
|
||||
],
|
||||
'image' => [
|
||||
'type' => 'image',
|
||||
'label' => t('Images'),
|
||||
'file_directory' => 'farm/plan/[date:custom:Y]-[date:custom:m]',
|
||||
'multiple' => TRUE,
|
||||
],
|
||||
'notes' => [
|
||||
'type' => 'text_long',
|
||||
'label' => t('Notes'),
|
||||
],
|
||||
];
|
||||
$fields = [];
|
||||
foreach ($field_info as $name => $info) {
|
||||
$fields[$name] = farm_field_base_field_definition($info);
|
||||
}
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function for generating a base field definition with farmOS opinions.
|
||||
*
|
||||
|
|
|
@ -24,6 +24,11 @@ function farm_field_entity_base_field_info(EntityTypeInterface $entity_type) {
|
|||
elseif ($entity_type->id() == 'log') {
|
||||
return farm_field_log_base_fields();
|
||||
}
|
||||
|
||||
// Add common base fields to all plan types.
|
||||
elseif ($entity_type->id() == 'plan') {
|
||||
return farm_field_plan_base_fields();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -31,8 +36,8 @@ function farm_field_entity_base_field_info(EntityTypeInterface $entity_type) {
|
|||
*/
|
||||
function farm_field_entity_base_field_info_alter(&$fields, EntityTypeInterface $entity_type) {
|
||||
|
||||
// Only alter asset and log fields.
|
||||
if (!in_array($entity_type->id(), ['asset', 'log'])) {
|
||||
// Only alter asset, log, and plan fields.
|
||||
if (!in_array($entity_type->id(), ['asset', 'log', 'plan'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies: { }
|
||||
id: test
|
||||
label: Test
|
||||
description: ''
|
||||
name_pattern: 'Test plan [plan:id]'
|
||||
workflow: plan_default
|
||||
new_revision: true
|
|
@ -6,4 +6,5 @@ core_version_requirement: ^9
|
|||
dependencies:
|
||||
- farm:asset
|
||||
- farm:farm_field
|
||||
- farm:plan
|
||||
- log:log
|
||||
|
|
|
@ -22,6 +22,7 @@ class FarmFieldTest extends KernelTestBase {
|
|||
protected static $modules = [
|
||||
'asset',
|
||||
'log',
|
||||
'plan',
|
||||
'farm_field',
|
||||
'farm_field_test',
|
||||
];
|
||||
|
@ -56,6 +57,15 @@ class FarmFieldTest extends KernelTestBase {
|
|||
$this->assertArrayHasKey('image', $fields);
|
||||
$this->assertArrayHasKey('notes', $fields);
|
||||
$this->assertArrayHasKey('owner', $fields);
|
||||
|
||||
// Load plan field storage definitions.
|
||||
$fields = $entity_field_manager->getFieldStorageDefinitions('plan');
|
||||
|
||||
// Confirm that all fields defined in farm_field_plan_base_fields() exist.
|
||||
$this->assertArrayHasKey('data', $fields);
|
||||
$this->assertArrayHasKey('file', $fields);
|
||||
$this->assertArrayHasKey('image', $fields);
|
||||
$this->assertArrayHasKey('notes', $fields);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -13,8 +13,8 @@ use Drupal\Core\Entity\EntityTypeInterface;
|
|||
function farm_flag_entity_base_field_info(EntityTypeInterface $entity_type) {
|
||||
$fields = [];
|
||||
|
||||
// Add flag field to assets and logs.
|
||||
if (in_array($entity_type->id(), ['asset', 'log'])) {
|
||||
// Add flag field to assets, logs, and plans.
|
||||
if (in_array($entity_type->id(), ['asset', 'log', 'plan'])) {
|
||||
|
||||
// Include helper functions.
|
||||
module_load_include('inc', 'farm_field', 'farm_field.base_fields');
|
||||
|
|
Loading…
Reference in a new issue