You are here

protected function EntityLanguageTestBase::toggleFieldTranslatability in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Entity/EntityLanguageTestBase.php \Drupal\KernelTests\Core\Entity\EntityLanguageTestBase::toggleFieldTranslatability()
  2. 10 core/tests/Drupal/KernelTests/Core/Entity/EntityLanguageTestBase.php \Drupal\KernelTests\Core\Entity\EntityLanguageTestBase::toggleFieldTranslatability()

Toggles field storage translatability.

Parameters

string $entity_type: The type of the entity fields are attached to.

1 call to EntityLanguageTestBase::toggleFieldTranslatability()
FieldTranslationSqlStorageTest::testFieldSqlStorage in core/tests/Drupal/KernelTests/Core/Entity/FieldTranslationSqlStorageTest.php
Tests field SQL storage.

File

core/tests/Drupal/KernelTests/Core/Entity/EntityLanguageTestBase.php, line 122

Class

EntityLanguageTestBase
Base class for language-aware entity tests.

Namespace

Drupal\KernelTests\Core\Entity

Code

protected function toggleFieldTranslatability($entity_type, $bundle) {
  $fields = [
    $this->fieldName,
    $this->untranslatableFieldName,
  ];
  foreach ($fields as $field_name) {
    $field = FieldConfig::loadByName($entity_type, $bundle, $field_name);
    $translatable = !$field
      ->isTranslatable();
    $field
      ->set('translatable', $translatable);
    $field
      ->save();
    $field = FieldConfig::loadByName($entity_type, $bundle, $field_name);
    $this
      ->assertEqual($field
      ->isTranslatable(), $translatable, 'Field translatability changed.');
  }
  \Drupal::cache('entity')
    ->deleteAll();
}