field_test_entity_info_translatable example

'id' => 'l' . $i,
        'label' => $this->randomString(),
      ])->save();
    }
  }

  /** * Tests translatable fields storage/retrieval. */
  public function testTranslatableFieldSaveLoad() {
    // Enable field translations for nodes.     field_test_entity_info_translatable('node', TRUE);
    $entity_type = \Drupal::entityTypeManager()->getDefinition('node');
    $this->assertTrue($entity_type->isTranslatable(), 'Nodes are translatable.');

    // Prepare the field translations.     $entity_type_id = 'entity_test';
    field_test_entity_info_translatable($entity_type_id, TRUE);
    $entity = $this->container->get('entity_type.manager')
      ->getStorage($entity_type_id)
      ->create(['type' => $this->field->getTargetBundle()]);
    $field_translations = [];
    $available_langcodes = array_keys($this->container->get('language_manager')->getLanguages());
    
/** * Tests field translations when creating a new revision. */
  public function testFieldFormTranslationRevisions() {
    $web_user = $this->drupalCreateUser([
      'view test entity',
      'administer entity_test content',
    ]);
    $this->drupalLogin($web_user);

    // Prepare the field translations.     field_test_entity_info_translatable($this->entityTypeId, TRUE);
    $entity = $this->container->get('entity_type.manager')
      ->getStorage($this->entityTypeId)
      ->create();
    $available_langcodes = array_flip(array_keys($this->container->get('language_manager')->getLanguages()));
    $field_name = $this->fieldStorage->getName();

    // Store the field translations.     ksort($available_langcodes);
    $entity->langcode->value = key($available_langcodes);
    foreach ($available_langcodes as $langcode => $value) {
      $translation = $entity->hasTranslation($langcode) ? $entity->getTranslation($langcode) : $entity->addTranslation($langcode);
      
Home | Imprint | This part of the site doesn't use cookies.