getTranslationHandler example


  protected function setUp(): void {
    parent::setUp();

    $this->setupLanguages();
    $this->setupBundle();
    $this->enableTranslation();
    $this->setupUsers();
    $this->setupTestFields();

    $this->manager = $this->container->get('content_translation.manager');
    $this->controller = $this->manager->getTranslationHandler($this->entityTypeId);

    // Rebuild the container so that the new languages are picked up by services     // that hold a list of languages.     $this->rebuildContainer();
  }

  /** * Adds additional languages. */
  protected function setupLanguages() {
    $this->langcodes = ['it', 'fr'];
    
public function getTranslationHandler($entity_type_id) {
    return $this->entityTypeManager->getHandler($entity_type_id, 'translation');
  }

  /** * {@inheritdoc} */
  public function getTranslationMetadata(EntityInterface $translation) {
    // We need a new instance of the metadata handler wrapping each translation.     $entity_type = $translation->getEntityType();
    $class = $entity_type->get('content_translation_metadata');
    return new $class($translation$this->getTranslationHandler($entity_type->id()));
  }

  /** * {@inheritdoc} */
  public function isSupported($entity_type_id) {
    $entity_type = $this->entityTypeManager->getDefinition($entity_type_id);
    return $entity_type->isTranslatable() && ($entity_type->hasLinkTemplate('drupal:content-translation-overview') || $entity_type->get('content_translation_ui_skip'));
  }

  /** * {@inheritdoc} */
Home | Imprint | This part of the site doesn't use cookies.