function TelephoneFieldTest::setUp
Same name in other branches
- 9 core/modules/telephone/tests/src/Functional/TelephoneFieldTest.php \Drupal\Tests\telephone\Functional\TelephoneFieldTest::setUp()
- 10 core/modules/telephone/tests/src/Functional/TelephoneFieldTest.php \Drupal\Tests\telephone\Functional\TelephoneFieldTest::setUp()
- 11.x core/modules/telephone/tests/src/Functional/TelephoneFieldTest.php \Drupal\Tests\telephone\Functional\TelephoneFieldTest::setUp()
Overrides BrowserTestBase::setUp
File
-
core/
modules/ telephone/ tests/ src/ Functional/ TelephoneFieldTest.php, line 42
Class
- TelephoneFieldTest
- Tests the creation of telephone fields.
Namespace
Drupal\Tests\telephone\FunctionalCode
protected function setUp() {
parent::setUp();
$this->drupalCreateContentType([
'type' => 'article',
]);
$this->webUser = $this->drupalCreateUser([
'create article content',
'edit own article content',
]);
$this->drupalLogin($this->webUser);
// Add the telephone field to the article content type.
FieldStorageConfig::create([
'field_name' => 'field_telephone',
'entity_type' => 'node',
'type' => 'telephone',
])->save();
FieldConfig::create([
'field_name' => 'field_telephone',
'label' => 'Telephone Number',
'entity_type' => 'node',
'bundle' => 'article',
])->save();
/** @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface $display_repository */
$display_repository = \Drupal::service('entity_display.repository');
$display_repository->getFormDisplay('node', 'article')
->setComponent('field_telephone', [
'type' => 'telephone_default',
'settings' => [
'placeholder' => '123-456-7890',
],
])
->save();
$display_repository->getViewDisplay('node', 'article')
->setComponent('field_telephone', [
'type' => 'telephone_link',
'weight' => 1,
])
->save();
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.