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

Convert group log bundle fields to base fields.

This commit is contained in:
Michael Stenta 2021-03-04 08:59:52 -05:00
parent aaaa291c14
commit 739cffaf5e
2 changed files with 62 additions and 40 deletions

View file

@ -0,0 +1,52 @@
<?php
/**
* @file
* Code for creating farmOS group membership base field definitions.
*/
/**
* Define log group base fields.
*/
function farm_group_log_base_fields() {
$fields = [];
// "Is group assignment" boolean field.
$options = [
'type' => 'boolean',
'label' => t('Is group assignment'),
'description' => t('If this log is a group assignment, any referenced assets will become members of the groups referenced below.'),
'weight' => [
'form' => 96,
],
'view_display_options' => [
'label' => 'inline',
'type' => 'hideable_boolean',
'settings' => [
'format' => 'default',
'format_custom_false' => '',
'format_custom_true' => '',
'hide_if_false' => TRUE,
],
'weight' => 96,
],
];
$fields['is_group_assignment'] = \Drupal::service('farm_field.factory')->baseFieldDefinition($options);
// Group reference field.
$options = [
'type' => 'entity_reference',
'label' => t('Groups'),
'description' => t('If this is a group assignment log, which groups should the referenced assets be assigned to?'),
'target_type' => 'asset',
'target_bundle' => 'group',
'multiple' => TRUE,
'weight' => [
'form' => 97,
'view' => 97,
],
];
$fields['group'] = \Drupal::service('farm_field.factory')->baseFieldDefinition($options);
return $fields;
}

View file

@ -8,47 +8,17 @@
use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Entity\EntityTypeInterface;
/** /**
* Implements hook_farm_entity_bundle_field_info(). * Implements hook_entity_base_field_info().
*/ */
function farm_group_farm_entity_bundle_field_info(EntityTypeInterface $entity_type, string $bundle) { function farm_group_entity_base_field_info(EntityTypeInterface $entity_type) {
$fields = []; module_load_include('inc', 'farm_group', 'farm_group.base_fields');
switch ($entity_type->id()) {
// Add an "Is group assignment" and a Group reference field to logs. // Build log base fields.
if ($entity_type->id() == 'log') { case 'log':
$options = [ return farm_group_log_base_fields();
'type' => 'boolean',
'label' => t('Is group assignment'), default:
'description' => t('If this log is a group assignment, any referenced assets will become members of the groups referenced below.'), return [];
'weight' => [
'form' => 96,
],
'view_display_options' => [
'label' => 'inline',
'type' => 'hideable_boolean',
'settings' => [
'format' => 'default',
'format_custom_false' => '',
'format_custom_true' => '',
'hide_if_false' => TRUE,
],
'weight' => 96,
],
];
$fields['is_group_assignment'] = \Drupal::service('farm_field.factory')->bundleFieldDefinition($options);
$options = [
'type' => 'entity_reference',
'label' => t('Groups'),
'description' => t('If this is a group assignment log, which groups should the referenced assets be assigned to?'),
'target_type' => 'asset',
'target_bundle' => 'group',
'multiple' => TRUE,
'weight' => [
'form' => 97,
'view' => 97,
],
];
$fields['group'] = \Drupal::service('farm_field.factory')->bundleFieldDefinition($options);
} }
return $fields;
} }