function EntityDefaultLanguageTest::createNode
Same name in other branches
- 8.9.x core/modules/language/tests/src/Kernel/EntityDefaultLanguageTest.php \Drupal\Tests\language\Kernel\EntityDefaultLanguageTest::createNode()
- 10 core/modules/language/tests/src/Kernel/EntityDefaultLanguageTest.php \Drupal\Tests\language\Kernel\EntityDefaultLanguageTest::createNode()
- 11.x core/modules/language/tests/src/Kernel/EntityDefaultLanguageTest.php \Drupal\Tests\language\Kernel\EntityDefaultLanguageTest::createNode()
Creates a new node of given type and language using Entity API.
Parameters
string $type: The node content type.
string $langcode: (optional) Language code to pass to entity create.
Return value
\Drupal\node\NodeInterface The node created.
1 call to EntityDefaultLanguageTest::createNode()
- EntityDefaultLanguageTest::testEntityTranslationDefaultLanguageViaCode in core/
modules/ language/ tests/ src/ Kernel/ EntityDefaultLanguageTest.php - Tests that default language code is properly set for new nodes.
File
-
core/
modules/ language/ tests/ src/ Kernel/ EntityDefaultLanguageTest.php, line 136
Class
- EntityDefaultLanguageTest
- Tests default language code is properly generated for entities.
Namespace
Drupal\Tests\language\KernelCode
protected function createNode($type, $langcode = NULL) {
$values = [
'type' => $type,
'title' => $this->randomString(),
];
if (!empty($langcode)) {
$values['langcode'] = $langcode;
}
$node = $this->container
->get('entity_type.manager')
->getStorage('node')
->create($values);
return $node;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.