function FieldTestHelper::entityInfoTranslatable

Same name and namespace in other branches
  1. 11.x core/modules/field/tests/modules/field_test/src/FieldTestHelper.php \Drupal\field_test\FieldTestHelper::entityInfoTranslatable()

Helper function to enable entity translations.

3 calls to FieldTestHelper::entityInfoTranslatable()
FieldTestEntityHooks::entityTypeAlter in core/modules/field/tests/modules/field_test/src/Hook/FieldTestEntityHooks.php
Implements hook_entity_type_alter().
TranslationTest::testTranslatableFieldSaveLoad in core/modules/field/tests/src/Kernel/TranslationTest.php
Tests translatable fields storage/retrieval.
TranslationWebTest::testFieldFormTranslationRevisions in core/modules/field/tests/src/Functional/TranslationWebTest.php
Tests field translations when creating a new revision.

File

core/modules/field/tests/modules/field_test/src/FieldTestHelper.php, line 18

Class

FieldTestHelper
Helper class for testing fields.

Namespace

Drupal\field_test

Code

public static function entityInfoTranslatable($entity_type_id = NULL, $translatable = NULL) : array {
  static $stored_value = [];
  if (isset($entity_type_id)) {
    $entity_definition_update_manager = \Drupal::entityDefinitionUpdateManager();
    $entity_type = $entity_definition_update_manager->getEntityType($entity_type_id);
    $stored_value[$entity_type_id] = $translatable;
    if ($translatable != $entity_type->isTranslatable()) {
      $entity_definition_update_manager->uninstallEntityType($entity_type);
      $entity_type->set('translatable', $translatable);
      $entity_definition_update_manager->installEntityType($entity_type);
    }
  }
  return $stored_value;
}

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