diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/StringFormatter.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/StringFormatter.php index 940267d..521a62a 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/StringFormatter.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/StringFormatter.php @@ -82,7 +82,7 @@ public static function create(ContainerInterface $container, array $configuratio public static function defaultSettings() { $options = parent::defaultSettings(); - $options['entity_link'] = FALSE; + $options['link_to_entity'] = FALSE; return $options; } @@ -94,10 +94,10 @@ public function settingsForm(array $form, FormStateInterface $form_state) { if ($this->fieldDefinition->getType() === 'string') { $entity_type = $this->entityManager->getDefinition($this->fieldDefinition->getTargetEntityTypeId()); - $form['entity_link'] = [ - '#title' => $this->t('Link to the @entity_label', ['@entity_label' => $entity_type->getLabel()]), + $form['link_to_entity'] = [ '#type' => 'checkbox', - '#default_value' => $this->getSetting('entity_link'), + '#title' => $this->t('Link to the @entity_label', ['@entity_label' => $entity_type->getLabel()]), + '#default_value' => $this->getSetting('link_to_entity'), ]; } @@ -109,9 +109,9 @@ public function settingsForm(array $form, FormStateInterface $form_state) { */ public function settingsSummary() { $build = []; - if ($this->getSetting('entity_link')) { + if ($this->fieldDefinition->getType() === 'string' && $this->getSetting('link_to_entity')) { $entity_type = $this->entityManager->getDefinition($this->fieldDefinition->getTargetEntityTypeId()); - $build['#markup'] = $this->t('Link to the @entity_label', ['@entity_label' => $entity_type->getLabel()]); + $build['#markup'] = $this->t('Linked to the @entity_label', ['@entity_label' => $entity_type->getLabel()]); } return $build; } @@ -122,17 +122,22 @@ public function settingsSummary() { public function viewElements(FieldItemListInterface $items) { $elements = array(); + $url = NULL; + // Add support to link to the entity itself. + if ($this->fieldDefinition->getType() === 'string' && $this->getSetting('link_to_entity') && ($entity = $items->getEntity()) && $entity->hasLinkTemplate('canonical')) { + $url = $entity->urlInfo(); + } + foreach ($items as $delta => $item) { // The text value has no text format assigned to it, so the user input // should equal the output, including newlines. $string = nl2br(String::checkPlain($item->value)); - // Add support to link to the entity itself. - if ($this->getSetting('entity_link') && ($entity = $items->getParent()->getValue()) && $entity->hasLinkTemplate('canonical')) { + if ($url) { $elements[$delta] = [ '#type' => 'link', '#title' => $string, - '#url' => $entity->urlInfo(), + '#url' => $url, ]; } else { diff --git a/core/modules/field/src/Tests/String/StringFormatterTest.php b/core/modules/field/src/Tests/String/StringFormatterTest.php index 59cb2a7..bc23148 100644 --- a/core/modules/field/src/Tests/String/StringFormatterTest.php +++ b/core/modules/field/src/Tests/String/StringFormatterTest.php @@ -129,7 +129,7 @@ public function testStringFormatter() { $this->display->setComponent($this->fieldName, [ 'type' => 'string', 'settings' => [ - 'entity_link' => TRUE, + 'link_to_entity' => TRUE, ], ]); $this->display->save(); diff --git a/core/modules/field_ui/src/Tests/EntityDisplayTest.php b/core/modules/field_ui/src/Tests/EntityDisplayTest.php index 82003d8..1ebd54f 100644 --- a/core/modules/field_ui/src/Tests/EntityDisplayTest.php +++ b/core/modules/field_ui/src/Tests/EntityDisplayTest.php @@ -69,7 +69,9 @@ public function testEntityDisplayCRUD() { 'label' => 'hidden', 'type' => 'string', 'weight' => -5, - 'settings' => array(), + 'settings' => array( + 'link_to_entity' => FALSE, + ), 'third_party_settings' => array(), ); $this->assertEqual($display->getComponents(), $expected); diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateFieldFormatterSettingsTest.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateFieldFormatterSettingsTest.php index 4759dc0..56eabf5 100644 --- a/core/modules/migrate_drupal/src/Tests/d6/MigrateFieldFormatterSettingsTest.php +++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateFieldFormatterSettingsTest.php @@ -178,7 +178,7 @@ public function testEntityDisplaySettings() { // Test phone field. $expected['weight'] = 9; $expected['type'] = 'string'; - $expected['settings'] = array(); + $expected['settings'] = array('link_to_entity' => FALSE); $component = $display->getComponent('field_test_phone'); $this->assertEqual($component, $expected, "node.story.teaser field_test_phone is of type telephone."); diff --git a/core/modules/simpletest/src/WebTestBase.php b/core/modules/simpletest/src/WebTestBase.php index 93a5047..f15e780 100644 --- a/core/modules/simpletest/src/WebTestBase.php +++ b/core/modules/simpletest/src/WebTestBase.php @@ -2308,16 +2308,6 @@ protected function getAbsoluteUrl($path) { } /** - * Get the current URL from the cURL handler. - * - * @return - * The current URL. - */ - protected function getUrl() { - return $this->url; - } - - /** * Gets the HTTP response headers of the requested page. * * Normally we are only interested in the headers returned by the last