I can fetch entity-type definition...

$entityType = \Drupal::entityTypeManager()

and I can fetch myself some of the bundle specific information...

if ($bundleName !== null) {
    $bundleConfig = $entityType->getBundleConfigDependency($bundleName);
    $config = HelperConfiguration::instance($bundleConfig["name"]);
    $configValues = $config->getConfigValue();

$configValues carries properties like description, preview_mode, display_submitted, even langcode, but what I cannot find, is how to find translatability status for a bundle.

On /admin/config/regional/content-language I can wonderfully manipulate translatability bulk-wise, from entity-coarseness, up to specific fields.

So, while there is an isTranslatable() method on EntityTypeInterface (and also onFieldDefinitionInterface), where is the bundle equivalent? Where is the rest of bundle's metadata hidden?

  • When I have entity, I can check upon $entity instanceof TranslatableInterface, right? So that could be used as a hack... just instantiate quickly one and test it....naah. – informatik-handwerk.de Apr 7 at 8:15
  • No, this wouldn't tell you whether the bundle is translatable, this information is stored in configuration. See the answer. – 4k4 Apr 7 at 9:32

To get the language specific configuration of a bundle use ContentLanguageSettings::loadByEntityTypeBundle.

For the translatability of the bundle, you'd use:

$settings = ContentLanguageSettings::loadByEntityTypeBundle($entity_type_id, $bundle_name);
$isBundleTranslatable = $settings->getThirdPartySetting("content_translation", "enabled");

You could also use ContentTranslationManager:

/** @var ContentTranslationManager $contentTranslationManager */
$contentTranslationManager = \Drupal::service('content_translation.manager');
$isBundleTranslatable = $contentTranslationManager->isEnabled($entity_type_id, $bundle_name);
| improve this answer | |
  • Huge thank you for your ever swift answers. But where do I go on from there? Does status() provide the translatability flag? – informatik-handwerk.de Apr 7 at 18:46
  • It's stored in the third party settings of that config, see api.drupal.org/api/drupal/… – 4k4 Apr 7 at 21:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.