function civicrm_entity_entity_bundle_info in CiviCRM Entity 8.3
Implements hook_entity_bundle_info().
File
- ./
civicrm_entity.module, line 144 - Module file for the CiviCRM Entity module.
Code
function civicrm_entity_entity_bundle_info() {
$transliteration = \Drupal::transliteration();
/** @var \Drupal\civicrm_entity\CiviCrmApiInterface $civicrm_api */
$civicrm_api = \Drupal::service('civicrm_entity.api');
$bundles = [];
$entity_types_with_bundles = array_filter(SupportedEntities::getInfo(), static function (array $civicrm_entity_info) {
return !empty($civicrm_entity_info['bundle property']);
});
foreach ($entity_types_with_bundles as $entity_type_id => $civicrm_entity_info) {
// We keep a bundle that is the same as the entity type ID. This allows us
// to create fields as if this entity has no bundles.
$bundles[$entity_type_id] = [
$entity_type_id => [
'label' => $civicrm_entity_info['civicrm entity label'],
],
];
$options = $civicrm_api
->getOptions($civicrm_entity_info['civicrm entity name'], $civicrm_entity_info['bundle property']);
foreach ($options as $option) {
$machine_name = SupportedEntities::optionToMachineName($option, $transliteration);
$bundles[$entity_type_id][$machine_name]['label'] = $option;
}
}
return $bundles;
}