protected function ContentTranslationTestBase::createEntity in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/content_translation/src/Tests/ContentTranslationTestBase.php \Drupal\content_translation\Tests\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.
10 calls to ContentTranslationTestBase::createEntity()
- CommentTranslationUITest::createEntity in core/
modules/ comment/ src/ Tests/ CommentTranslationUITest.php - Creates the entity to be translated.
- ContentTranslationMetadataFieldsTest::testSetTranslatable in core/
modules/ content_translation/ src/ Tests/ ContentTranslationMetadataFieldsTest.php - Tests setting translatable metadata fields.
- ContentTranslationMetadataFieldsTest::testSkipUntranslatable in core/
modules/ content_translation/ src/ Tests/ ContentTranslationMetadataFieldsTest.php - Tests skipping setting non translatable metadata fields.
- ContentTranslationUITestBase::doTestBasicTranslation in core/
modules/ content_translation/ src/ Tests/ ContentTranslationUITestBase.php - Tests the basic translation workflow.
- ContentTranslationWorkflowsTest::setupEntity in core/
modules/ content_translation/ src/ Tests/ ContentTranslationWorkflowsTest.php - Creates a test entity and translate it.
3 methods override ContentTranslationTestBase::createEntity()
- CommentTranslationUITest::createEntity in core/
modules/ comment/ src/ Tests/ CommentTranslationUITest.php - Creates the entity to be translated.
- MenuLinkContentTranslationUITest::createEntity in core/
modules/ menu_link_content/ src/ Tests/ MenuLinkContentTranslationUITest.php - Creates the entity to be translated.
- ShortcutTranslationUITest::createEntity in core/
modules/ shortcut/ src/ Tests/ ShortcutTranslationUITest.php - Creates the entity to be translated.
File
- core/
modules/ content_translation/ src/ Tests/ ContentTranslationTestBase.php, line 220 - Contains \Drupal\content_translation\Tests\ContentTranslationTestBase.
Class
- ContentTranslationTestBase
- Base class for content translation tests.
Namespace
Drupal\content_translation\TestsCode
protected function createEntity($values, $langcode, $bundle_name = NULL) {
$entity_values = $values;
$entity_values['langcode'] = $langcode;
$entity_type = \Drupal::entityManager()
->getDefinition($this->entityTypeId);
if ($bundle_key = $entity_type
->getKey('bundle')) {
$entity_values[$bundle_key] = $bundle_name ?: $this->bundle;
}
$controller = $this->container
->get('entity.manager')
->getStorage($this->entityTypeId);
if (!$controller instanceof SqlContentEntityStorage) {
foreach ($values as $property => $value) {
if (is_array($value)) {
$entity_values[$property] = array(
$langcode => $value,
);
}
}
}
$entity = entity_create($this->entityTypeId, $entity_values);
$entity
->save();
return $entity
->id();
}