Created
September 28, 2014 22:44
-
-
Save larowlan/b2be691f5c54ddca7140 to your computer and use it in GitHub Desktop.
link formatter diff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/core/modules/link/src/Plugin/Field/FieldFormatter/LinkFormatter.php b/core/modules/link/src/Plugin/Field/FieldFormatter/LinkFormatter.php | |
| index f1d179f..4b51e9d 100644 | |
| --- a/core/modules/link/src/Plugin/Field/FieldFormatter/LinkFormatter.php | |
| +++ b/core/modules/link/src/Plugin/Field/FieldFormatter/LinkFormatter.php | |
| @@ -13,6 +13,7 @@ | |
| use Drupal\Core\Form\FormStateInterface; | |
| use Drupal\Core\Url; | |
| use Drupal\link\LinkItemInterface; | |
| +use Symfony\Component\HttpFoundation\Request; | |
| /** | |
| * Plugin implementation of the 'link' formatter. | |
| @@ -206,7 +207,16 @@ protected function buildUrl(LinkItemInterface $item) { | |
| } | |
| if ($item->isExternal()) { | |
| - $url = Url::unrouted($item->url, $options); | |
| + if (parse_url($item->url, PHP_URL_SCHEME)) { | |
| + $url = Url::unrouted($item->url, $options); | |
| + } | |
| + elseif ($item->url == '<front>') { | |
| + $url = new Url('<front>'); | |
| + } | |
| + else { | |
| + // No base path - assume internal. | |
| + $url = Url::createFromRequest(Request::create('/' . ltrim($item->url, '/'))); | |
| + } | |
| } | |
| else { | |
| $url = Url::routed($item->route_name, (array) $item->route_parameters, (array) $options); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment