function hook_farm_entity_bundle_field_info in farmOS 2.x
Allows modules to add field definitions to asset, log, and plan bundles.
@todo https://www.drupal.org/project/farm/issues/3194206
Parameters
\Drupal\Core\Entity\EntityTypeInterface $entity_type: The entity type object.
string $bundle: The machine name of the bundle.
Return value
\Drupal\entity\BundleFieldDefinition[] Returns an array of BundleFieldDefinition objects.
5 functions implement hook_farm_entity_bundle_field_info()
Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.
- farm_entity_contrib_test_farm_entity_bundle_field_info in modules/
core/ entity/ tests/ modules/ farm_entity_contrib_test/ farm_entity_contrib_test.module - Implements hook_farm_entity_bundle_field_info().
- farm_entity_test_farm_entity_bundle_field_info in modules/
core/ entity/ tests/ modules/ farm_entity_test/ farm_entity_test.module - Implements hook_farm_entity_bundle_field_info().
- farm_equipment_farm_entity_bundle_field_info in modules/
asset/ equipment/ farm_equipment.module - Implements hook_farm_entity_bundle_field_info().
- farm_quick_farm_entity_bundle_field_info in modules/
core/ quick/ farm_quick.module - Implements hook_farm_entity_bundle_field_info().
- farm_sensor_listener_farm_entity_bundle_field_info in modules/
asset/ sensor/ modules/ listener/ farm_sensor_listener.module - Implements hook_farm_entity_bundle_field_info().
3 invocations of hook_farm_entity_bundle_field_info()
- FarmEntityBundlePluginHandler::getFieldDefinitions in modules/
core/ entity/ src/ BundlePlugin/ FarmEntityBundlePluginHandler.php - FarmEntityBundlePluginHandler::getFieldStorageDefinitions in modules/
core/ entity/ src/ BundlePlugin/ FarmEntityBundlePluginHandler.php - farm_entity_entity_field_storage_info_alter in modules/
core/ entity/ farm_entity.module - Implements hook_entity_field_storage_info_alter().
File
- modules/
core/ entity/ farm_entity.api.php, line 30 - Hooks provided by farm_entity.
Code
function hook_farm_entity_bundle_field_info(\Drupal\Core\Entity\EntityTypeInterface $entity_type, string $bundle) {
$fields = [];
// Add a new string field to Input Logs.
if ($entity_type
->id() == 'log' && $bundle == 'input') {
$options = [
'type' => 'string',
'label' => t('My new field'),
'description' => t('My field description.'),
'weight' => [
'form' => 10,
'view' => 10,
],
];
$fields['myfield'] = \Drupal::service('farm_field.factory')
->bundleFieldDefinition($options);
}
return $fields;
}