trait ContentTranslationTestTrait

Same name and namespace in other branches
  1. 11.x core/modules/content_translation/tests/src/Traits/ContentTranslationTestTrait.php \Drupal\Tests\content_translation\Traits\ContentTranslationTestTrait

Provides an API to programmatically manage content translation in tests.

Hierarchy

16 files declare their use of ContentTranslationTestTrait
ContentTranslationContextualLinksTest.php in core/modules/content_translation/tests/src/Functional/ContentTranslationContextualLinksTest.php
ContentTranslationLanguageChangeTest.php in core/modules/content_translation/tests/src/Functional/ContentTranslationLanguageChangeTest.php
DisplayFeedTranslationTest.php in core/modules/views/tests/src/Functional/Plugin/DisplayFeedTranslationTest.php
EntityReferenceFieldTranslatedReferenceViewTest.php in core/modules/field/tests/src/Functional/EntityReference/EntityReferenceFieldTranslatedReferenceViewTest.php
FileOnTranslatedEntityTest.php in core/modules/file/tests/src/Functional/FileOnTranslatedEntityTest.php

... See full list

File

core/modules/content_translation/tests/src/Traits/ContentTranslationTestTrait.php, line 13

Namespace

Drupal\Tests\content_translation\Traits
View source
trait ContentTranslationTestTrait {
    use LanguageTestTrait;
    
    /**
     * Enables content translation for the given entity type bundle.
     *
     * @param string $entity_type_id
     *   The ID of the entity type.
     * @param string $bundle
     *   The bundle name.
     * @param string|null $default_langcode
     *   The language code to use as the default language.
     */
    public function enableContentTranslation(string $entity_type_id, string $bundle, ?string $default_langcode = LanguageInterface::LANGCODE_SITE_DEFAULT) : void {
        static::enableBundleTranslation($entity_type_id, $bundle, $default_langcode);
        $content_translation_manager = $this->container
            ->get('content_translation.manager');
        $content_translation_manager->setEnabled($entity_type_id, $bundle, TRUE);
        $content_translation_manager->setBundleTranslationSettings($entity_type_id, $bundle, [
            'untranslatable_fields_hide' => FALSE,
        ]);
    }

}

Members

Title Sort descending Modifiers Object type Summary
ContentTranslationTestTrait::enableContentTranslation public function Enables content translation for the given entity type bundle.
LanguageTestTrait::createLanguageFromLangcode public static function Creates a configurable language object from a langcode.
LanguageTestTrait::disableBundleTranslation public static function Disables translations for the given entity type bundle.
LanguageTestTrait::enableBundleTranslation public static function Enables translations for the given entity type bundle.
LanguageTestTrait::setFieldTranslatable public static function Sets and saves a given field instance translation status.

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