Loading core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php +1 −1 Original line number Diff line number Diff line Loading @@ -286,7 +286,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen // Exposing the attributes array in the widget is left for alternate and more // advanced field widgets. $element['options']['attributes'] = [ $element['attributes'] = [ '#type' => 'value', '#tree' => TRUE, '#value' => !empty($items[$delta]->options['attributes']) ? $items[$delta]->options['attributes'] : [], Loading core/modules/link/tests/src/Functional/LinkFieldTest.php +0 −72 Original line number Diff line number Diff line Loading @@ -841,78 +841,6 @@ public function testNoLinkUri() { $this->assertStringContainsString($expected_link, $output); } /** * Test attributes preserved on save. * * Make sure that attributes are retained when the link is saved via the UI. */ public function testAttributesOnLink() { $field_name = mb_strtolower($this->randomMachineName()); $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' => LinkItemInterface::LINK_INTERNAL, ], ])->save(); $this->container->get('entity_type.manager') ->getStorage('entity_form_display') ->load('entity_test.entity_test.default') ->setComponent($field_name, [ 'type' => 'link_default', ]) ->save(); EntityViewDisplay::create([ 'targetEntityType' => 'entity_test', 'bundle' => 'entity_test', 'mode' => 'full', 'status' => TRUE, ])->setComponent($field_name, [ 'type' => 'link', ]) ->save(); // Test a link with attributes. $edit = [ "{$field_name}[0][title]" => 'Link with attributes.', "{$field_name}[0][uri]" => '<front>', ]; $this->drupalGet('entity_test/add'); $this->submitForm($edit, t('Save')); preg_match('|entity_test/manage/(\d+)|', $this->getUrl(), $match); $id = $match[1]; $entity = EntityTest::load($id); $field = $entity->get($field_name)->first(); $attribute_value = mb_strtolower($this->randomMachineName()); $field->set('options', ['attributes' => ['custom-attribute' => $attribute_value]]); $entity->save(); $output = $this->renderTestEntity($id); $this->assertStringContainsString($attribute_value, $output); $this->drupalGet($entity->toUrl('edit-form')); $this->submitForm([], 'Save'); $output = $this->renderTestEntity($id); $this->assertStringContainsString($attribute_value, $output); } /** * Renders a test_entity and returns the output. * Loading Loading
core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php +1 −1 Original line number Diff line number Diff line Loading @@ -286,7 +286,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen // Exposing the attributes array in the widget is left for alternate and more // advanced field widgets. $element['options']['attributes'] = [ $element['attributes'] = [ '#type' => 'value', '#tree' => TRUE, '#value' => !empty($items[$delta]->options['attributes']) ? $items[$delta]->options['attributes'] : [], Loading
core/modules/link/tests/src/Functional/LinkFieldTest.php +0 −72 Original line number Diff line number Diff line Loading @@ -841,78 +841,6 @@ public function testNoLinkUri() { $this->assertStringContainsString($expected_link, $output); } /** * Test attributes preserved on save. * * Make sure that attributes are retained when the link is saved via the UI. */ public function testAttributesOnLink() { $field_name = mb_strtolower($this->randomMachineName()); $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' => LinkItemInterface::LINK_INTERNAL, ], ])->save(); $this->container->get('entity_type.manager') ->getStorage('entity_form_display') ->load('entity_test.entity_test.default') ->setComponent($field_name, [ 'type' => 'link_default', ]) ->save(); EntityViewDisplay::create([ 'targetEntityType' => 'entity_test', 'bundle' => 'entity_test', 'mode' => 'full', 'status' => TRUE, ])->setComponent($field_name, [ 'type' => 'link', ]) ->save(); // Test a link with attributes. $edit = [ "{$field_name}[0][title]" => 'Link with attributes.', "{$field_name}[0][uri]" => '<front>', ]; $this->drupalGet('entity_test/add'); $this->submitForm($edit, t('Save')); preg_match('|entity_test/manage/(\d+)|', $this->getUrl(), $match); $id = $match[1]; $entity = EntityTest::load($id); $field = $entity->get($field_name)->first(); $attribute_value = mb_strtolower($this->randomMachineName()); $field->set('options', ['attributes' => ['custom-attribute' => $attribute_value]]); $entity->save(); $output = $this->renderTestEntity($id); $this->assertStringContainsString($attribute_value, $output); $this->drupalGet($entity->toUrl('edit-form')); $this->submitForm([], 'Save'); $output = $this->renderTestEntity($id); $this->assertStringContainsString($attribute_value, $output); } /** * Renders a test_entity and returns the output. * Loading