function LinkFieldTest::doTestLinkTypeOnLinkWidget
Same name in other branches
- 9 core/modules/link/tests/src/Functional/LinkFieldTest.php \Drupal\Tests\link\Functional\LinkFieldTest::doTestLinkTypeOnLinkWidget()
- 10 core/modules/link/tests/src/Functional/LinkFieldTest.php \Drupal\Tests\link\Functional\LinkFieldTest::doTestLinkTypeOnLinkWidget()
Tests '#link_type' property exists on 'link_default' widget.
Make sure the 'link_default' widget exposes a '#link_type' property on its element. Modules can use it to understand if a text form element is a link and also which LinkItemInterface::LINK_* is (EXTERNAL, GENERIC, INTERNAL).
1 call to LinkFieldTest::doTestLinkTypeOnLinkWidget()
- LinkFieldTest::testLinkField in core/
modules/ link/ tests/ src/ Functional/ LinkFieldTest.php - Tests the functionality and rendering of the link field.
File
-
core/
modules/ link/ tests/ src/ Functional/ LinkFieldTest.php, line 864
Class
- LinkFieldTest
- Tests link field widgets and formatters.
Namespace
Drupal\Tests\link\FunctionalCode
protected function doTestLinkTypeOnLinkWidget() : void {
$link_type = LinkItemInterface::LINK_EXTERNAL;
$field_name = $this->randomMachineName();
// Create a field with settings to validate.
$this->fieldStorage = FieldStorageConfig::create([
'field_name' => $field_name,
'entity_type' => 'entity_test',
'type' => 'link',
'cardinality' => 1,
]);
$this->fieldStorage
->save();
FieldConfig::create([
'field_storage' => $this->fieldStorage,
'label' => 'Read more about this entity',
'bundle' => 'entity_test',
'settings' => [
'title' => DRUPAL_OPTIONAL,
'link_type' => $link_type,
],
])
->save();
$this->container
->get('entity_type.manager')
->getStorage('entity_form_display')
->load('entity_test.entity_test.default')
->setComponent($field_name, [
'type' => 'link_default',
])
->save();
$form = \Drupal::service('entity.form_builder')->getForm(EntityTest::create());
$this->assertEquals($link_type, $form[$field_name]['widget'][0]['uri']['#link_type']);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.