function ContentTranslationHooks::entityBundleInfoAlter

Implements hook_entity_bundle_info_alter().

Attributes

#[Hook('entity_bundle_info_alter', order: Order::First)]

File

core/modules/content_translation/src/Hook/ContentTranslationHooks.php, line 225

Class

ContentTranslationHooks
Hook implementations for content_translation.

Namespace

Drupal\content_translation\Hook

Code

public function entityBundleInfoAlter(&$bundles) : void {
  /** @var \Drupal\content_translation\ContentTranslationManagerInterface $content_translation_manager */
  $content_translation_manager = \Drupal::service('content_translation.manager');
  foreach ($bundles as $entity_type_id => &$info) {
    foreach ($info as $bundle => &$bundle_info) {
      $bundle_info['translatable'] = $content_translation_manager->isEnabled($entity_type_id, $bundle);
      if ($bundle_info['translatable'] && $content_translation_manager instanceof BundleTranslationSettingsInterface) {
        $settings = $content_translation_manager->getBundleTranslationSettings($entity_type_id, $bundle);
        $bundle_info['untranslatable_fields.default_translation_affected'] = !empty($settings['untranslatable_fields_hide']);
      }
    }
  }
  // Always hide untranslatable field widgets if pending revision support is
  // enabled otherwise changes in pending
  // revisions might be overridden by changes in later default revisions.
  // This can't use
  // Drupal\content_translation\ContentTranslationManager::isPendingRevisionSupportEnabled()
  // since that depends on entity bundle information to be completely built.
  if (\Drupal::moduleHandler()->moduleExists('content_moderation')) {
    foreach (Workflow::loadMultipleByType('content_moderation') as $workflow) {
      /** @var \Drupal\content_moderation\Plugin\WorkflowType\ContentModeration $plugin */
      $plugin = $workflow->getTypePlugin();
      foreach ($plugin->getEntityTypes() as $entity_type_id) {
        foreach ($plugin->getBundlesForEntityType($entity_type_id) as $bundle_id) {
          if (isset($bundles[$entity_type_id][$bundle_id])) {
            $bundles[$entity_type_id][$bundle_id]['untranslatable_fields.default_translation_affected'] = TRUE;
          }
        }
      }
    }
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.