function ContentTranslationTestBase::createEntity
Same name in other branches
- 8.9.x core/modules/content_translation/src/Tests/ContentTranslationTestBase.php \Drupal\content_translation\Tests\ContentTranslationTestBase::createEntity()
- 8.9.x core/modules/content_translation/tests/src/Functional/ContentTranslationTestBase.php \Drupal\Tests\content_translation\Functional\ContentTranslationTestBase::createEntity()
- 10 core/modules/content_translation/tests/src/Functional/ContentTranslationTestBase.php \Drupal\Tests\content_translation\Functional\ContentTranslationTestBase::createEntity()
- 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 - 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.
3 methods override ContentTranslationTestBase::createEntity()
- CommentTranslationUITest::createEntity in core/
modules/ comment/ tests/ src/ Functional/ CommentTranslationUITest.php - MenuLinkContentTranslationUITest::createEntity in core/
modules/ menu_link_content/ tests/ src/ Functional/ MenuLinkContentTranslationUITest.php - ShortcutTranslationUITest::createEntity in core/
modules/ shortcut/ tests/ src/ Functional/ ShortcutTranslationUITest.php
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\FunctionalCode
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.