function NodeFieldMultilingualTest::setUp
Overrides BrowserTestBase::setUp
File
-
core/
modules/ node/ tests/ src/ Functional/ NodeFieldMultilingualTest.php, line 35
Class
- NodeFieldMultilingualTest
- Tests multilingual support for fields.
Namespace
Drupal\Tests\node\FunctionalCode
protected function setUp() : void {
parent::setUp();
// Create Basic page node type.
$this->drupalCreateContentType([
'type' => 'page',
'name' => 'Basic page',
]);
// Setup users.
$admin_user = $this->drupalCreateUser([
'administer languages',
'administer content types',
'access administration pages',
'create page content',
'edit own page content',
]);
$this->drupalLogin($admin_user);
// Add a new language.
ConfigurableLanguage::createFromLangcode('it')->save();
// Enable URL language detection and selection.
$this->config('language.types')
->set('negotiation.language_interface.enabled', [
'language-url' => -8,
'language-selected' => 12,
])
->save();
// Set "Basic page" content type to use multilingual support.
\Drupal::entityTypeManager()->getStorage('language_content_settings')
->create([
'target_entity_type_id' => 'node',
'target_bundle' => 'page',
'language_alterable' => TRUE,
])
->save();
// Make node body translatable.
$field_storage = FieldStorageConfig::loadByName('node', 'body');
$field_storage->setTranslatable(TRUE);
$field_storage->save();
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.