function ContentTranslationTestBase::createEntity
Same name in other branches
- 9 core/modules/content_translation/tests/src/Functional/ContentTranslationTestBase.php \Drupal\Tests\content_translation\Functional\ContentTranslationTestBase::createEntity()
- 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()
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.
19 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.
- ContentTranslationNewTranslationWithExistingRevisionsTest::testCreatingNewDraftDoesNotInvokeDeleteHook in core/
modules/ content_translation/ tests/ src/ Functional/ ContentTranslationNewTranslationWithExistingRevisionsTest.php - Test translation delete hooks are not invoked.
- ContentTranslationNewTranslationWithExistingRevisionsTest::testDraftTranslationIsNotDeleted in core/
modules/ content_translation/ tests/ src/ Functional/ ContentTranslationNewTranslationWithExistingRevisionsTest.php - Tests a translation with a draft is not deleted.
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 217
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.