function ContentTranslationTestBase::createEntity

Same name in other branches
  1. 8.9.x core/modules/content_translation/src/Tests/ContentTranslationTestBase.php \Drupal\content_translation\Tests\ContentTranslationTestBase::createEntity()
  2. 8.9.x core/modules/content_translation/tests/src/Functional/ContentTranslationTestBase.php \Drupal\Tests\content_translation\Functional\ContentTranslationTestBase::createEntity()
  3. 10 core/modules/content_translation/tests/src/Functional/ContentTranslationTestBase.php \Drupal\Tests\content_translation\Functional\ContentTranslationTestBase::createEntity()
  4. 11.x core/modules/content_translation/tests/src/Functional/ContentTranslationTestBase.php \Drupal\Tests\content_translation\Functional\ContentTranslationTestBase::createEntity()

Creates the entity to be translated.

Parameters

array $values: An array of initial values for the entity.

string $langcode: The initial language code of the entity.

string $bundle_name: (optional) The entity bundle, if the entity uses bundles. Defaults to NULL. If left NULL, $this->bundle will be used.

Return value

string The entity id.

17 calls to ContentTranslationTestBase::createEntity()
CommentTranslationUITest::createEntity in core/modules/comment/tests/src/Functional/CommentTranslationUITest.php
Creates the entity to be translated.
ContentTranslationMetadataFieldsTest::testSetTranslatable in core/modules/content_translation/tests/src/Functional/ContentTranslationMetadataFieldsTest.php
Tests setting translatable metadata fields.
ContentTranslationMetadataFieldsTest::testSkipUntranslatable in core/modules/content_translation/tests/src/Functional/ContentTranslationMetadataFieldsTest.php
Tests skipping setting non translatable metadata fields.
ContentTranslationOutdatedRevisionTranslationTest::testFlagAsOutdatedHidden in core/modules/content_translation/tests/src/Functional/ContentTranslationOutdatedRevisionTranslationTest.php
Tests that outdated revision translations work correctly.
ContentTranslationRevisionTranslationDeletionTest::doTestOverview in core/modules/content_translation/tests/src/Functional/ContentTranslationRevisionTranslationDeletionTest.php
Performs a test run.

... See full list

3 methods override ContentTranslationTestBase::createEntity()
CommentTranslationUITest::createEntity in core/modules/comment/tests/src/Functional/CommentTranslationUITest.php
Creates the entity to be translated.
MenuLinkContentTranslationUITest::createEntity in core/modules/menu_link_content/tests/src/Functional/MenuLinkContentTranslationUITest.php
Creates the entity to be translated.
ShortcutTranslationUITest::createEntity in core/modules/shortcut/tests/src/Functional/ShortcutTranslationUITest.php
Creates the entity to be translated.

File

core/modules/content_translation/tests/src/Functional/ContentTranslationTestBase.php, line 219

Class

ContentTranslationTestBase
Base class for content translation tests.

Namespace

Drupal\Tests\content_translation\Functional

Code

protected function createEntity($values, $langcode, $bundle_name = NULL) {
    $entity_values = $values;
    $entity_values['langcode'] = $langcode;
    $entity_type = \Drupal::entityTypeManager()->getDefinition($this->entityTypeId);
    if ($bundle_key = $entity_type->getKey('bundle')) {
        $entity_values[$bundle_key] = $bundle_name ?: $this->bundle;
    }
    $storage = $this->container
        ->get('entity_type.manager')
        ->getStorage($this->entityTypeId);
    if (!$storage instanceof SqlContentEntityStorage) {
        foreach ($values as $property => $value) {
            if (is_array($value)) {
                $entity_values[$property] = [
                    $langcode => $value,
                ];
            }
        }
    }
    $entity = $this->container
        ->get('entity_type.manager')
        ->getStorage($this->entityTypeId)
        ->create($entity_values);
    $entity->save();
    return $entity->id();
}

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