A function to get entity translatable bundles.
Note that for comment entity type it will return the same as for node as comment bundles have no use (i.e. in queries).
string $entity_type: Drupal entity type.
array Array of key => values, where key is type and value its label.
function getTranslatableBundles($entity_type) {
// If given entity type does not have entity translations enabled, no reason
// to continue.
$enabled_types = \Drupal::service('plugin.manager.tmgmt.source')
->createInstance('content')
->getItemTypes();
if (!isset($enabled_types[$entity_type])) {
return array();
}
$translatable_bundle_types = array();
$content_translation_manager = \Drupal::service('content_translation.manager');
foreach (\Drupal::service('entity_type.bundle.info')
->getBundleInfo($entity_type) as $bundle_type => $bundle_definition) {
if ($content_translation_manager
->isEnabled($entity_type, $bundle_type)) {
$translatable_bundle_types[$bundle_type] = $bundle_definition['label'];
}
}
return $translatable_bundle_types;
}