function TelephoneFieldTest::setUp

Same name in other branches
  1. 8.9.x core/modules/telephone/tests/src/Functional/TelephoneFieldTest.php \Drupal\Tests\telephone\Functional\TelephoneFieldTest::setUp()
  2. 10 core/modules/telephone/tests/src/Functional/TelephoneFieldTest.php \Drupal\Tests\telephone\Functional\TelephoneFieldTest::setUp()
  3. 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 43

Class

TelephoneFieldTest
Tests the creation of telephone fields.

Namespace

Drupal\Tests\telephone\Functional

Code

protected function setUp() : void {
    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.