function EntityLanguageTestBase::toggleFieldTranslatability

Same name in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Entity/EntityLanguageTestBase.php \Drupal\KernelTests\Core\Entity\EntityLanguageTestBase::toggleFieldTranslatability()
  2. 8.9.x core/tests/Drupal/KernelTests/Core/Entity/EntityLanguageTestBase.php \Drupal\KernelTests\Core\Entity\EntityLanguageTestBase::toggleFieldTranslatability()
  3. 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.

string $bundle: The bundle of the entity.

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 132

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->assertEquals($translatable, $field->isTranslatable(), 'Field translatability changed.');
    }
    \Drupal::cache('entity')->deleteAll();
}

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