diff --git a/core/modules/dblog/src/Controller/DbLogController.php b/core/modules/dblog/src/Controller/DbLogController.php index 37429e8..2ef2d06 100644 --- a/core/modules/dblog/src/Controller/DbLogController.php +++ b/core/modules/dblog/src/Controller/DbLogController.php @@ -254,11 +254,11 @@ public function eventDetails($event_id) { ), array( array('data' => $this->t('Location'), 'header' => TRUE), - $this->l($dblog->location, Url::fromUri('base://' . $dblog->location)), + $this->l($dblog->location, $dblog->location ? Url::fromUri('base://' . $dblog->location) : Url::fromRoute('')), ), array( array('data' => $this->t('Referrer'), 'header' => TRUE), - $this->l($dblog->referer, Url::fromUri('base://' . $dblog->referer)), + $this->l($dblog->referer, $dblog->referer ? Url::fromUri('base://' . $dblog->referer) : Url::fromRoute('')), ), array( array('data' => $this->t('Message'), 'header' => TRUE), diff --git a/core/modules/path/src/Controller/PathController.php b/core/modules/path/src/Controller/PathController.php index 30b15c4..ebf4805 100644 --- a/core/modules/path/src/Controller/PathController.php +++ b/core/modules/path/src/Controller/PathController.php @@ -85,9 +85,9 @@ public function adminOverview(Request $request) { $destination = drupal_get_destination(); foreach ($this->aliasStorage->getAliasesForAdminListing($header, $keys) as $data) { $row = array(); - $row['data']['alias'] = $this->l(truncate_utf8($data->alias, 50, FALSE, TRUE), Url::fromUri('base://' . $data->source, array( + $row['data']['alias'] = _l(truncate_utf8($data->alias, 50, FALSE, TRUE), $data->source, array( 'attributes' => array('title' => $data->alias), - ))); + )); $row['data']['source'] = $this->l(truncate_utf8($data->source, 50, FALSE, TRUE), Url::fromUri('base://' . $data->source, array( 'alias' => TRUE, 'attributes' => array('title' => $data->source), diff --git a/core/modules/user/src/Plugin/views/field/LinkEdit.php b/core/modules/user/src/Plugin/views/field/LinkEdit.php index 11f3292..bb288631 100644 --- a/core/modules/user/src/Plugin/views/field/LinkEdit.php +++ b/core/modules/user/src/Plugin/views/field/LinkEdit.php @@ -28,8 +28,7 @@ protected function renderLink(EntityInterface $entity, ResultRow $values) { $text = !empty($this->options['text']) ? $this->options['text'] : $this->t('Edit'); - $this->options['alter']['path'] = $entity->getSystemPath('edit-form'); - $this->options['alter']['query'] = drupal_get_destination(); + $this->options['alter']['url'] = $entity->urlInfo('edit-form', ['query' => ['destination' => drupal_get_destination()]]); return $text; } diff --git a/core/modules/user/src/Tests/UserAdminTest.php b/core/modules/user/src/Tests/UserAdminTest.php index 8305146..900090c 100644 --- a/core/modules/user/src/Tests/UserAdminTest.php +++ b/core/modules/user/src/Tests/UserAdminTest.php @@ -52,8 +52,6 @@ function testUserAdmin() { $this->assertText($admin_user->getUsername(), 'Found Admin user on admin users page'); // Test for existence of edit link in table. - // @todo This cannot be converted to \Drupal::l() until - // https://www.drupal.org/node/2345725 is resolved. $link = $user_a->link(t('Edit'), 'edit-form', array('query' => array('destination' => 'admin/people'))); $this->assertRaw($link, 'Found user A edit link on admin users page'); diff --git a/core/modules/views/src/Plugin/views/field/FieldPluginBase.php b/core/modules/views/src/Plugin/views/field/FieldPluginBase.php index 486ef5a..106a1f7 100644 --- a/core/modules/views/src/Plugin/views/field/FieldPluginBase.php +++ b/core/modules/views/src/Plugin/views/field/FieldPluginBase.php @@ -88,6 +88,13 @@ var $additional_fields = array(); /** + * The link generator. + * + * @var \Drupal\Core\Utility\LinkGeneratorInterface + */ + protected $linkGenerator; + + /** * Overrides Drupal\views\Plugin\views\HandlerBase::init(). */ public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) { @@ -1345,6 +1352,10 @@ protected function renderAsLink($alter, $text, $tokens) { 'absolute' => !empty($alter['absolute']) ? TRUE : FALSE, ); + $alter += [ + 'path' => NULL + ]; + // $path will be run through check_url() by _l() so we do not need to // sanitize it ourselves. $path = $alter['path']; @@ -1376,7 +1387,7 @@ protected function renderAsLink($alter, $text, $tokens) { // If the path is empty do not build a link around the given text and return // it as is. // http://www.example.com URLs will not have a $url['path'], so check host as well. - if (empty($url['path']) && empty($url['host']) && empty($url['fragment'])) { + if (empty($url['path']) && empty($url['host']) && empty($url['fragment']) && empty($url['url'])) { return $text; } @@ -1483,7 +1494,12 @@ protected function renderAsLink($alter, $text, $tokens) { $options['entity_type'] = $alter['entity_type']; } - $value .= _l($text, $path, $options); + if (isset($options['url']) && $options['url'] instanceof Url) { + $value .= $this->linkGenerator()->generate($text, $options['url']); + } + else { + $value .= _l($text, $path, $options); + } if (!empty($alter['suffix'])) { $value .= Xss::filterAdmin(strtr($alter['suffix'], $tokens)); @@ -1718,6 +1734,17 @@ public static function trimText($alter, $value) { return $value; } + /** + * Gets the link generator. + * + * @return \Drupal\Core\Utility\LinkGeneratorInterface + */ + protected function linkGenerator() { + if (!isset($this->linkGenerator)) { + $this->linkGenerator = \Drupal::linkGenerator(); + } + return $this->linkGenerator; + } } /** diff --git a/core/modules/views/src/Plugin/views/field/Links.php b/core/modules/views/src/Plugin/views/field/Links.php index 5912664..5e4f1ec 100644 --- a/core/modules/views/src/Plugin/views/field/Links.php +++ b/core/modules/views/src/Plugin/views/field/Links.php @@ -72,15 +72,19 @@ protected function getLinks() { } $title = $this->view->field[$field]->last_render_text; $path = ''; + $url = NULL; if (!empty($this->view->field[$field]->options['alter']['path'])) { $path = $this->view->field[$field]->options['alter']['path']; } + elseif (!empty($this->view->field[$field]->options['alter']['url']) && $this->view->field[$field]->options['alter']['url'] instanceof UrlObject) { + $url = $this->view->field[$field]->options['alter']['url']; + } // Make sure that tokens are replaced for this paths as well. $tokens = $this->getRenderTokens(array()); $path = strip_tags(decode_entities(strtr($path, $tokens))); $links[$field] = array( - 'url' => UrlObject::fromUri('base://' . $path), + 'url' => $path ? UrlObject::fromUri('base://' . $path) : $url, 'title' => $title, ); if (!empty($this->options['destination'])) {