function farm_entity_test_farm_entity_bundle_field_info in farmOS 2.x
Implements hook_farm_entity_bundle_field_info().
File
- modules/
core/ entity/ tests/ modules/ farm_entity_test/ farm_entity_test.module, line 31 - Contains farm_entity_test.module.
Code
function farm_entity_test_farm_entity_bundle_field_info(EntityTypeInterface $entity_type, string $bundle) {
$fields = [];
// Add a new bundle field to test logs.
if ($entity_type
->id() == 'log' && in_array($bundle, [
'test',
'test_override',
])) {
$options = [
'type' => 'string',
'label' => t('Test hook bundle field'),
];
$fields['test_hook_bundle_field'] = \Drupal::service('farm_field.factory')
->bundleFieldDefinition($options);
}
// Add bundle specific fields to all log types.
if ($entity_type
->id() == 'log') {
$options = [
'type' => 'string',
'label' => t('Test bundle specific field for: @bundle', [
'@bundle' => $bundle,
]),
];
$field_name = 'test_hook_bundle_' . $bundle . '_specific_field';
$fields[$field_name] = \Drupal::service('farm_field.factory')
->bundleFieldDefinition($options);
}
return $fields;
}