createTranslatableEntity example

// In order to reflect the changes for a multilingual site in the container     // we have to rebuild it.     ConfigurableLanguage::create(['id' => 'es'])->save();
    ConfigurableLanguage::create(['id' => 'fr'])->save();

    $config = $this->config('language.negotiation');
    $config->set('url.prefixes', ['en' => 'en', 'es' => 'es', 'fr' => 'fr'])
      ->save();

    \Drupal::service('kernel')->rebuildContainer();

    $this->createTranslatableEntity();
  }

  /** * Ensures that entity URLs in a language have the right language prefix. */
  public function testEntityUrlLanguage() {
    $this->assertStringContainsString('/en/entity_test/' . $this->entity->id()$this->entity->toUrl()->toString());
    $this->assertStringContainsString('/es/entity_test/' . $this->entity->id()$this->entity->getTranslation('es')->toUrl()->toString());
    $this->assertStringContainsString('/fr/entity_test/' . $this->entity->id()$this->entity->getTranslation('fr')->toUrl()->toString());
  }

  

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

    ConfigurableLanguage::create(['id' => 'es'])->save();
    ConfigurableLanguage::create(['id' => 'fr'])->save();

    // In order to reflect the changes for a multilingual site in the container     // we have to rebuild it.     $this->rebuildContainer();

    $this->createTranslatableEntity();

    $user = $this->drupalCreateUser(['view test entity']);
    $this->drupalLogin($user);
  }

  /** * Tests default with content language remaining same as interface language. */
  public function testDefaultConfiguration() {
    $translation = $this->entity;
    $this->drupalGet($translation->toUrl());
    

  public function testCanonicalAlternateTags() {
    /** @var \Drupal\Core\Language\LanguageManagerInterface $languageManager */
    $languageManager = $this->container->get('language_manager');
    /** @var \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager */
    $entityTypeManager = $this->container->get('entity_type.manager');

    $definition = $entityTypeManager->getDefinition('entity_test_mul');
    $this->assertTrue($definition->hasLinkTemplate('canonical'), 'Canonical link template found for entity_test.');

    $entity = $this->createTranslatableEntity();
    $url_base = $entity->toUrl('canonical')
      ->setAbsolute();

    $langcodes_all = $this->langcodes;
    $langcodes_all[] = $languageManager
      ->getDefaultLanguage()
      ->getId();

    /** @var \Drupal\Core\Url[] $urls */
    $urls = array_map(
      function D$langcode) use ($url_base$languageManager) {
        
Home | Imprint | This part of the site doesn't use cookies.