diff --git a/core/includes/theme.inc b/core/includes/theme.inc
index 976158b..c726d07 100644
--- a/core/includes/theme.inc
+++ b/core/includes/theme.inc
@@ -949,7 +949,7 @@ function template_preprocess_status_messages(&$variables) {
* jQuery('li:has("a.active")')
*
* @see \Drupal\Core\Utility\LinkGenerator
- * @see \Drupal\Core\Utility\LinkGenerator::generateFromUrl()
+ * @see \Drupal\Core\Utility\LinkGenerator::generate()
* @see system_page_build()
*/
function template_preprocess_links(&$variables) {
diff --git a/core/lib/Drupal.php b/core/lib/Drupal.php
index 1844043..b355847 100644
--- a/core/lib/Drupal.php
+++ b/core/lib/Drupal.php
@@ -567,10 +567,10 @@ public static function linkGenerator() {
* does not match the requirement.
*
* @see \Drupal\Core\Routing\UrlGeneratorInterface::generateFromRoute()
- * @see \Drupal\Core\Utility\LinkGeneratorInterface::generateFromUrl()
+ * @see \Drupal\Core\Utility\LinkGeneratorInterface::generate()
*/
public static function l($text, Url $url) {
- return static::$container->get('link_generator')->generateFromUrl($text, $url);
+ return static::$container->get('link_generator')->generate($text, $url);
}
/**
diff --git a/core/lib/Drupal/Core/Link.php b/core/lib/Drupal/Core/Link.php
index 58959e1..35dddee 100644
--- a/core/lib/Drupal/Core/Link.php
+++ b/core/lib/Drupal/Core/Link.php
@@ -124,7 +124,7 @@ public function setUrl(Url $url) {
* Generates the HTML for this Link object.
*/
public function toString() {
- return $this->getLinkGenerator()->generateFromUrl($this->getText(), $this->getUrl());
+ return $this->getLinkGenerator()->generateFromLink($this);
}
}
diff --git a/core/lib/Drupal/Core/Routing/LinkGeneratorTrait.php b/core/lib/Drupal/Core/Routing/LinkGeneratorTrait.php
index 9869c57..f86c02f 100644
--- a/core/lib/Drupal/Core/Routing/LinkGeneratorTrait.php
+++ b/core/lib/Drupal/Core/Routing/LinkGeneratorTrait.php
@@ -38,7 +38,7 @@
* An HTML string containing a link to the given route and parameters.
*/
protected function l($text, $route_name, array $parameters = array(), array $options = array()) {
- return $this->getLinkGenerator()->generateFromUrl($text, new Url($route_name, $parameters, $options));
+ return $this->getLinkGenerator()->generate($text, new Url($route_name, $parameters, $options));
}
/**
diff --git a/core/lib/Drupal/Core/Template/TwigExtension.php b/core/lib/Drupal/Core/Template/TwigExtension.php
index e71d9d0..20c71e6 100644
--- a/core/lib/Drupal/Core/Template/TwigExtension.php
+++ b/core/lib/Drupal/Core/Template/TwigExtension.php
@@ -210,7 +210,7 @@ public function getUrlFromPath($path, $options = array()) {
*/
public function getLink($text, $url) {
if ($url instanceof Url) {
- return $this->linkGenerator->generateFromUrl($text, $url);
+ return $this->linkGenerator->generate($text, $url);
}
else {
// @todo Convert once https://www.drupal.org/node/2306901 is in
diff --git a/core/lib/Drupal/Core/Utility/LinkGenerator.php b/core/lib/Drupal/Core/Utility/LinkGenerator.php
index 15ee6b5..cc0f134 100644
--- a/core/lib/Drupal/Core/Utility/LinkGenerator.php
+++ b/core/lib/Drupal/Core/Utility/LinkGenerator.php
@@ -11,6 +11,7 @@
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Component\Utility\String;
use Drupal\Core\Extension\ModuleHandlerInterface;
+use Drupal\Core\Link;
use Drupal\Core\Path\AliasManagerInterface;
use Drupal\Core\Routing\UrlGeneratorInterface;
use Drupal\Core\Template\Attribute;
@@ -50,6 +51,13 @@ public function __construct(UrlGeneratorInterface $url_generator, ModuleHandlerI
/**
* {@inheritdoc}
+ */
+ public function generateFromLink(Link $link) {
+ return $this->generate($link->getText(), $link->getUrl());
+ }
+
+ /**
+ * {@inheritdoc}
*
* For anonymous users, the "active" class will be calculated on the server,
* because most sites serve each anonymous user the same cached page anyway.
@@ -60,7 +68,7 @@ public function __construct(UrlGeneratorInterface $url_generator, ModuleHandlerI
*
* @see system_page_build()
*/
- public function generateFromUrl($text, Url $url) {
+ public function generate($text, Url $url) {
// Start building a structured representation of our link to be altered later.
$variables = array(
// @todo Inject the service when drupal_render() is converted to one.
diff --git a/core/lib/Drupal/Core/Utility/LinkGeneratorInterface.php b/core/lib/Drupal/Core/Utility/LinkGeneratorInterface.php
index 1cb2a22..ba47197 100644
--- a/core/lib/Drupal/Core/Utility/LinkGeneratorInterface.php
+++ b/core/lib/Drupal/Core/Utility/LinkGeneratorInterface.php
@@ -63,6 +63,17 @@
* Thrown when a parameter value for a placeholder is not correct because it
* does not match the requirement.
*/
- public function generateFromUrl($text, Url $url);
+ public function generate($text, Url $url);
+
+ /**
+ * Renders a link from a link object.
+ *
+ * @param \Drupal\Core\Link $link
+ * A link object to convert to a string.
+ *
+ * @return string
+ * An HTML string containing a link to the given link.
+ */
+ public function generateFromLink(Link $link);
}
diff --git a/core/modules/aggregator/src/Controller/AggregatorController.php b/core/modules/aggregator/src/Controller/AggregatorController.php
index 0f70800..cd583c2 100644
--- a/core/modules/aggregator/src/Controller/AggregatorController.php
+++ b/core/modules/aggregator/src/Controller/AggregatorController.php
@@ -121,7 +121,7 @@ public function adminOverview() {
$rows = array();
foreach ($feeds as $feed) {
$row = array();
- $row[] = $this->getLinkGenerator()->generateFromUrl($feed->label(), $feed->urlInfo());
+ $row[] = $this->getLinkGenerator()->generate($feed->label(), $feed->urlInfo());
$row[] = $this->dateFormatter->formatInterval($entity_manager->getStorage('aggregator_item')->getItemCount($feed), '1 item', '@count items');
$last_checked = $feed->getLastCheckedTime();
$refresh_rate = $feed->getRefreshRate();
diff --git a/core/modules/book/book.module b/core/modules/book/book.module
index 5fd5d21..b716fee 100644
--- a/core/modules/book/book.module
+++ b/core/modules/book/book.module
@@ -521,7 +521,7 @@ function theme_book_link(array $variables) {
/** @var \Drupal\Core\Url $url */
$url = $element['#url'];
$url->setOptions($element['#localized_options'] + $url->getOptions());
- $output = \Drupal::linkGenerator()->generateFromUrl($element['#title'], $url);
+ $output = \Drupal::linkGenerator()->generate($element['#title'], $url);
return '
' . $output . $sub_menu . "\n";
}
diff --git a/core/modules/book/src/Controller/BookController.php b/core/modules/book/src/Controller/BookController.php
index dd467b9..4a0c6f5 100644
--- a/core/modules/book/src/Controller/BookController.php
+++ b/core/modules/book/src/Controller/BookController.php
@@ -77,7 +77,7 @@ public function adminOverview() {
$url->setOptions($book['options']);
}
$row = array(
- $this->getLinkGenerator()->generateFromUrl($book['title'], $url),
+ $this->getLinkGenerator()->generate($book['title'], $url),
);
$links = array();
$links['edit'] = array(
@@ -110,7 +110,7 @@ public function adminOverview() {
public function bookRender() {
$book_list = array();
foreach ($this->bookManager->getAllBooks() as $book) {
- $book_list[] = $this->getLinkGenerator()->generateFromUrl($book['title'], $book['url']);
+ $book_list[] = $this->getLinkGenerator()->generate($book['title'], $book['url']);
}
return array(
'#theme' => 'item_list',
diff --git a/core/modules/book/src/Form/BookAdminEditForm.php b/core/modules/book/src/Form/BookAdminEditForm.php
index 973f44a..34983bb 100644
--- a/core/modules/book/src/Form/BookAdminEditForm.php
+++ b/core/modules/book/src/Form/BookAdminEditForm.php
@@ -121,7 +121,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
$node->book['link_title'] = $values['title'];
$node->setNewRevision();
$node->save();
- $this->logger('content')->notice('book: updated %title.', array('%title' => $node->label(), 'link' => $this->getLinkGenerator()->generateFromUrl($this->t('View'), $node->urlInfo())));
+ $this->logger('content')->notice('book: updated %title.', array('%title' => $node->label(), 'link' => $this->getLinkGenerator()->generate($this->t('View'), $node->urlInfo())));
}
}
}
diff --git a/core/modules/book/src/Tests/BookTest.php b/core/modules/book/src/Tests/BookTest.php
index 335e6b5..61d082a 100644
--- a/core/modules/book/src/Tests/BookTest.php
+++ b/core/modules/book/src/Tests/BookTest.php
@@ -190,21 +190,21 @@ function checkBookNode(EntityInterface $node, $nodes, $previous = FALSE, $up = F
/** @var \Drupal\Core\Url $url */
$url = $previous->urlInfo();
$url->setOptions(array('html' => TRUE, 'attributes' => array('rel' => array('prev'), 'title' => t('Go to previous page'))));
- $this->assertRaw(\Drupal::linkGenerator()->generateFromUrl('‹ ' . $previous->label(), $url), 'Previous page link found.');
+ $this->assertRaw(\Drupal::linkGenerator()->generate('‹ ' . $previous->label(), $url), 'Previous page link found.');
}
if ($up) {
/** @var \Drupal\Core\Url $url */
$url = $up->urlInfo();
$url->setOptions(array('html'=> TRUE, 'attributes' => array('title' => t('Go to parent page'))));
- $this->assertRaw(\Drupal::linkGenerator()->generateFromUrl('Up', $url), 'Up page link found.');
+ $this->assertRaw(\Drupal::linkGenerator()->generate('Up', $url), 'Up page link found.');
}
if ($next) {
/** @var \Drupal\Core\Url $url */
$url = $next->urlInfo();
$url->setOptions(array('html'=> TRUE, 'attributes' => array('rel' => array('next'), 'title' => t('Go to next page'))));
- $this->assertRaw(\Drupal::linkGenerator()->generateFromUrl($next->label() . ' ›', $url), 'Next page link found.');
+ $this->assertRaw(\Drupal::linkGenerator()->generate($next->label() . ' ›', $url), 'Next page link found.');
}
// Compute the expected breadcrumb.
diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module
index 3b020c6..9eb1e06 100644
--- a/core/modules/comment/comment.module
+++ b/core/modules/comment/comment.module
@@ -735,9 +735,9 @@ function template_preprocess_comment(&$variables) {
$attributes = $uri->getOption('attributes') ?: array();
$attributes += array('class' => array('permalink'), 'rel' => 'bookmark');
$uri->setOption('attributes', $attributes);
- $variables['title'] = \Drupal::linkGenerator()->generateFromUrl($comment->getSubject(), $uri);
+ $variables['title'] = \Drupal::linkGenerator()->generate($comment->getSubject(), $uri);
- $variables['permalink'] = \Drupal::linkGenerator()->generateFromUrl(t('Permalink'), $comment->permalink());
+ $variables['permalink'] = \Drupal::linkGenerator()->generate(t('Permalink'), $comment->permalink());
}
$variables['submitted'] = t('Submitted by !username on !datetime', array('!username' => $variables['author'], '!datetime' => $variables['created']));
@@ -764,8 +764,8 @@ function template_preprocess_comment(&$variables) {
$attributes = $permalink_uri_parent->getOption('attributes') ?: array();
$attributes += array('class' => array('permalink'), 'rel' => 'bookmark');
$permalink_uri_parent->setOption('attributes', $attributes);
- $variables['parent_title'] = \Drupal::linkGenerator()->generateFromUrl($comment_parent->getSubject(), $permalink_uri_parent);
- $variables['parent_permalink'] = \Drupal::linkGenerator()->generateFromUrl(t('Parent permalink'), $permalink_uri_parent);
+ $variables['parent_title'] = \Drupal::linkGenerator()->generate($comment_parent->getSubject(), $permalink_uri_parent);
+ $variables['parent_permalink'] = \Drupal::linkGenerator()->generate(t('Parent permalink'), $permalink_uri_parent);
$variables['parent'] = t('In reply to !parent_title by !parent_username',
array('!parent_username' => $variables['parent_author'], '!parent_title' => $variables['parent_title']));
}
diff --git a/core/modules/comment/src/CommentForm.php b/core/modules/comment/src/CommentForm.php
index 84f1dce..fec0662 100644
--- a/core/modules/comment/src/CommentForm.php
+++ b/core/modules/comment/src/CommentForm.php
@@ -372,7 +372,7 @@ public function save(array $form, FormStateInterface $form_state) {
// Add a log entry.
$logger->notice('Comment posted: %subject.', array(
'%subject' => $comment->getSubject(),
- 'link' => $this->getLinkGenerator()->generateFromUrl(t('View'), $comment->urlInfo()->setOption('fragment', 'comment-' . $comment->id()))
+ 'link' => $this->getLinkGenerator()->generate(t('View'), $comment->urlInfo()->setOption('fragment', 'comment-' . $comment->id()))
));
// Explain the approval queue if necessary.
diff --git a/core/modules/content_translation/src/Controller/ContentTranslationController.php b/core/modules/content_translation/src/Controller/ContentTranslationController.php
index 991d51c..e82054b 100644
--- a/core/modules/content_translation/src/Controller/ContentTranslationController.php
+++ b/core/modules/content_translation/src/Controller/ContentTranslationController.php
@@ -125,7 +125,7 @@ public function overview(Request $request, $entity_type_id = NULL) {
$link = isset($links->links[$langcode]['url']) ? $links->links[$langcode] : array('url' => $entity->urlInfo());
if (!empty($link['url'])) {
$link['url']->setOption('language', $language);
- $row_title = $this->getLinkGenerator()->generateFromUrl($label, $link['url']);
+ $row_title = $this->getLinkGenerator()->generate($label, $link['url']);
}
if (empty($link['url'])) {
diff --git a/core/modules/field_ui/src/FieldStorageConfigListBuilder.php b/core/modules/field_ui/src/FieldStorageConfigListBuilder.php
index 626647c..718b1d4 100644
--- a/core/modules/field_ui/src/FieldStorageConfigListBuilder.php
+++ b/core/modules/field_ui/src/FieldStorageConfigListBuilder.php
@@ -112,7 +112,7 @@ public function buildRow(EntityInterface $field_storage) {
$usage = array();
foreach ($field_storage->getBundles() as $bundle) {
if ($route_info = FieldUI::getOverviewRouteInfo($field_storage->entity_type, $bundle)) {
- $usage[] = \Drupal::linkGenerator()->generateFromUrl($this->bundles[$field_storage->entity_type][$bundle]['label'], $route_info);
+ $usage[] = \Drupal::linkGenerator()->generate($this->bundles[$field_storage->entity_type][$bundle]['label'], $route_info);
}
else {
$usage[] = $this->bundles[$field_storage->entity_type][$bundle]['label'];
diff --git a/core/modules/forum/forum.module b/core/modules/forum/forum.module
index 5e966d4..ad44572 100644
--- a/core/modules/forum/forum.module
+++ b/core/modules/forum/forum.module
@@ -541,7 +541,7 @@ function template_preprocess_forums(&$variables) {
}
else {
$variables['topics'][$id]->moved = FALSE;
- $variables['topics'][$id]->title_link = \Drupal::linkGenerator()->generateFromUrl($topic->getTitle(), $topic->urlInfo());
+ $variables['topics'][$id]->title_link = \Drupal::linkGenerator()->generate($topic->getTitle(), $topic->urlInfo());
$variables['topics'][$id]->message = '';
}
$forum_submitted = array('#theme' => 'forum_submitted', '#topic' => (object) array(
diff --git a/core/modules/link/link.module b/core/modules/link/link.module
index d33181e..0e10e95 100644
--- a/core/modules/link/link.module
+++ b/core/modules/link/link.module
@@ -66,7 +66,7 @@ function template_preprocess_link_formatter_link_separate(&$variables) {
}
if (!$variables['url']->isExternal()) {
- $variables['link'] = \Drupal::linkGenerator()->generateFromUrl($variables['url_title'], $variables['url']);
+ $variables['link'] = \Drupal::linkGenerator()->generate($variables['url_title'], $variables['url']);
}
else {
$variables['link'] = l($variables['url_title'], $variables['url']->getPath(), $variables['url']->getOptions());
diff --git a/core/modules/menu_ui/src/MenuForm.php b/core/modules/menu_ui/src/MenuForm.php
index 46faf55..720aa2b 100644
--- a/core/modules/menu_ui/src/MenuForm.php
+++ b/core/modules/menu_ui/src/MenuForm.php
@@ -269,7 +269,7 @@ protected function buildOverviewTreeForm($tree, $delta) {
$id = 'menu_plugin_id:' . $link->getPluginId();
$form[$id]['#item'] = $element;
$form[$id]['#attributes'] = $link->isEnabled() ? array('class' => array('menu-enabled')) : array('class' => array('menu-disabled'));
- $form[$id]['title']['#markup'] = $this->linkGenerator->generateFromUrl($link->getTitle(), $link->getUrlObject(), $link->getOptions());
+ $form[$id]['title']['#markup'] = $this->linkGenerator->generate($link->getTitle(), $link->getUrlObject(), $link->getOptions());
if (!$link->isEnabled()) {
$form[$id]['title']['#markup'] .= ' (' . $this->t('disabled') . ')';
}
diff --git a/core/modules/node/node.admin.inc b/core/modules/node/node.admin.inc
index e6b955e..922f579 100644
--- a/core/modules/node/node.admin.inc
+++ b/core/modules/node/node.admin.inc
@@ -128,7 +128,7 @@ function _node_mass_update_batch_process(array $nodes, array $updates, $load, $r
$node = _node_mass_update_helper($node, $updates);
// Store result for post-processing in the finished callback.
- $context['results'][] = \Drupal::linkGenerator()->generateFromUrl($node->label(), $node->urlInfo());
+ $context['results'][] = \Drupal::linkGenerator()->generate($node->label(), $node->urlInfo());
// Update our progress information.
$context['sandbox']['progress']++;
diff --git a/core/modules/node/src/NodeForm.php b/core/modules/node/src/NodeForm.php
index a3c484f..52ad9cd 100644
--- a/core/modules/node/src/NodeForm.php
+++ b/core/modules/node/src/NodeForm.php
@@ -408,7 +408,7 @@ public function save(array $form, FormStateInterface $form_state) {
$node = $this->entity;
$insert = $node->isNew();
$node->save();
- $node_link = $this->getLinkGenerator()->generateFromUrl(t('View'), $node->urlInfo());
+ $node_link = $this->getLinkGenerator()->generate(t('View'), $node->urlInfo());
$context = array('@type' => $node->getType(), '%title' => $node->label(), 'link' => $node_link);
$t_args = array('@type' => node_get_type_label($node), '%title' => $node->label());
diff --git a/core/modules/search/src/Tests/SearchConfigSettingsFormTest.php b/core/modules/search/src/Tests/SearchConfigSettingsFormTest.php
index fde250a..4702961 100644
--- a/core/modules/search/src/Tests/SearchConfigSettingsFormTest.php
+++ b/core/modules/search/src/Tests/SearchConfigSettingsFormTest.php
@@ -48,7 +48,7 @@ protected function setUp() {
// Link the node to itself to test that it's only indexed once. The content
// also needs the word "pizza" so we can use it as the search keyword.
$body_key = 'body[0][value]';
- $edit[$body_key] = \Drupal::linkGenerator()->generateFromUrl($node->label(), $node->urlInfo()) . ' pizza sandwich';
+ $edit[$body_key] = \Drupal::linkGenerator()->generate($node->label(), $node->urlInfo()) . ' pizza sandwich';
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save and keep published'));
$this->container->get('plugin.manager.search')->createInstance('node_search')->updateIndex();
diff --git a/core/modules/shortcut/src/Form/SetCustomize.php b/core/modules/shortcut/src/Form/SetCustomize.php
index 89ddf4e..a9a53d6 100644
--- a/core/modules/shortcut/src/Form/SetCustomize.php
+++ b/core/modules/shortcut/src/Form/SetCustomize.php
@@ -52,7 +52,7 @@ public function form(array $form, FormStateInterface $form_state) {
foreach ($this->entity->getShortcuts() as $shortcut) {
$id = $shortcut->id();
$form['shortcuts']['links'][$id]['#attributes']['class'][] = 'draggable';
- $form['shortcuts']['links'][$id]['name']['#markup'] = $this->getLinkGenerator()->generateFromUrl($shortcut->getTitle(), $shortcut->getUrl());
+ $form['shortcuts']['links'][$id]['name']['#markup'] = $this->getLinkGenerator()->generate($shortcut->getTitle(), $shortcut->getUrl());
$form['shortcuts']['links'][$id]['#weight'] = $shortcut->getWeight();
$form['shortcuts']['links'][$id]['weight'] = array(
'#type' => 'weight',
diff --git a/core/modules/statistics/src/Tests/StatisticsReportsTest.php b/core/modules/statistics/src/Tests/StatisticsReportsTest.php
index 91b5fa4..09a2c00 100644
--- a/core/modules/statistics/src/Tests/StatisticsReportsTest.php
+++ b/core/modules/statistics/src/Tests/StatisticsReportsTest.php
@@ -49,7 +49,7 @@ function testPopularContentBlock() {
$this->assertText('All time', 'Found the all time popular content.');
$this->assertText('Last viewed', 'Found the last viewed popular content.');
- $this->assertRaw(\Drupal::linkGenerator()->generateFromUrl($node->label(), $node->urlInfo()), 'Found link to visited node.');
+ $this->assertRaw(\Drupal::linkGenerator()->generate($node->label(), $node->urlInfo()), 'Found link to visited node.');
}
}
diff --git a/core/modules/system/src/Tests/Theme/EngineTwigTest.php b/core/modules/system/src/Tests/Theme/EngineTwigTest.php
index a98bb3c..acfd1d1 100644
--- a/core/modules/system/src/Tests/Theme/EngineTwigTest.php
+++ b/core/modules/system/src/Tests/Theme/EngineTwigTest.php
@@ -73,7 +73,7 @@ public function testTwigLinkGenerator() {
$link_generator = $this->container->get('link_generator');
$expected = [
- 'link via the linkgenerator: ' . $link_generator->generateFromUrl('register', new Url('user.register')),
+ 'link via the linkgenerator: ' . $link_generator->generate('register', new Url('user.register')),
];
$content = $this->getRawContent();
diff --git a/core/modules/system/system.admin.inc b/core/modules/system/system.admin.inc
index 57edc26..de42408 100644
--- a/core/modules/system/system.admin.inc
+++ b/core/modules/system/system.admin.inc
@@ -59,7 +59,7 @@ function template_preprocess_admin_block_content(&$variables) {
$variables['attributes']['class'][] = 'compact';
}
foreach ($variables['content'] as $key => $item) {
- $variables['content'][$key]['link'] = \Drupal::linkGenerator()->generateFromUrl($item['title'], $item['url']);
+ $variables['content'][$key]['link'] = \Drupal::linkGenerator()->generate($item['title'], $item['url']);
if (!$compact && isset($item['description'])) {
$variables['content'][$key]['description'] = Xss::filterAdmin($item['description']);
}
diff --git a/core/modules/taxonomy/src/TermForm.php b/core/modules/taxonomy/src/TermForm.php
index 39ebb01..8a95ccf 100644
--- a/core/modules/taxonomy/src/TermForm.php
+++ b/core/modules/taxonomy/src/TermForm.php
@@ -136,7 +136,7 @@ public function save(array $form, FormStateInterface $form_state) {
$result = $term->save();
- $link = $this->getLinkGenerator()->generateFromUrl($this->t('Edit'), $term->urlInfo('edit-form'));
+ $link = $this->getLinkGenerator()->generate($this->t('Edit'), $term->urlInfo('edit-form'));
switch ($result) {
case SAVED_NEW:
drupal_set_message($this->t('Created new term %term.', array('%term' => $term->getName())));
diff --git a/core/modules/taxonomy/src/Tests/TermIndexTest.php b/core/modules/taxonomy/src/Tests/TermIndexTest.php
index a6a6ea5..5c7dcc3 100644
--- a/core/modules/taxonomy/src/Tests/TermIndexTest.php
+++ b/core/modules/taxonomy/src/Tests/TermIndexTest.php
@@ -217,6 +217,6 @@ function testTaxonomyTermHierarchyBreadcrumbs() {
// Verify that the page breadcrumbs include a link to the parent term.
$this->drupalGet('taxonomy/term/' . $term1->id());
- $this->assertRaw(\Drupal::linkGenerator()->generateFromUrl($term2->getName(), $term2->urlInfo()), 'Parent term link is displayed when viewing the node.');
+ $this->assertRaw(\Drupal::linkGenerator()->generate($term2->getName(), $term2->urlInfo()), 'Parent term link is displayed when viewing the node.');
}
}
diff --git a/core/modules/taxonomy/src/Tests/Views/TaxonomyFieldTidTest.php b/core/modules/taxonomy/src/Tests/Views/TaxonomyFieldTidTest.php
index 29f6f3b..ffade98 100644
--- a/core/modules/taxonomy/src/Tests/Views/TaxonomyFieldTidTest.php
+++ b/core/modules/taxonomy/src/Tests/Views/TaxonomyFieldTidTest.php
@@ -28,7 +28,7 @@ function testViewsHandlerTidField() {
$this->executeView($view);
$actual = $view->field['name']->advancedRender($view->result[0]);
- $expected = \Drupal::linkGenerator()->generateFromUrl($this->term1->label(), $this->term1->urlInfo());
+ $expected = \Drupal::linkGenerator()->generate($this->term1->label(), $this->term1->urlInfo());
$this->assertEqual($expected, $actual);
}
diff --git a/core/modules/tracker/tracker.pages.inc b/core/modules/tracker/tracker.pages.inc
index f68cad7..8281fcc 100644
--- a/core/modules/tracker/tracker.pages.inc
+++ b/core/modules/tracker/tracker.pages.inc
@@ -74,7 +74,7 @@ function tracker_page($account = NULL) {
if ($new = \Drupal::service('comment.manager')->getCountNewComments($node)) {
$comments .= '
';
- $comments .= \Drupal::linkGenerator()->generateFromUrl(format_plural($new, '1 new', '@count new'), $node->urlInfo()->setOptions(array('fragment' => 'new')));
+ $comments .= \Drupal::linkGenerator()->generate(format_plural($new, '1 new', '@count new'), $node->urlInfo()->setOptions(array('fragment' => 'new')));
}
}
@@ -85,7 +85,7 @@ function tracker_page($account = NULL) {
$row = array(
'type' => String::checkPlain(node_get_type_label($node)),
- 'title' => array('data' => \Drupal::linkGenerator()->generateFromUrl($node->getTitle(), $node->urlInfo()) . ' ' . drupal_render($mark_build)),
+ 'title' => array('data' => \Drupal::linkGenerator()->generate($node->getTitle(), $node->urlInfo()) . ' ' . drupal_render($mark_build)),
'author' => array('data' => array('#theme' => 'username', '#account' => $node->getOwner())),
'replies' => array('class' => array('replies'), 'data' => $comments),
'last updated' => array('data' => t('!time ago', array('!time' => \Drupal::service('date.formatter')->formatInterval(REQUEST_TIME - $node->last_activity)))),
diff --git a/core/tests/Drupal/Tests/Core/DrupalTest.php b/core/tests/Drupal/Tests/Core/DrupalTest.php
index 03f6174..988cf6c 100644
--- a/core/tests/Drupal/Tests/Core/DrupalTest.php
+++ b/core/tests/Drupal/Tests/Core/DrupalTest.php
@@ -278,7 +278,7 @@ public function testLinkGenerator() {
/**
* Tests the l() method.
*
- * @see \Drupal\Core\Utility\LinkGeneratorInterface::generateFromUrl()
+ * @see \Drupal\Core\Utility\LinkGeneratorInterface::generate()
*/
public function testL() {
$route_parameters = array('test_parameter' => 'test');
@@ -286,7 +286,7 @@ public function testL() {
$generator = $this->getMock('Drupal\Core\Utility\LinkGeneratorInterface');
$url = new Url('test_route', $route_parameters, $options);
$generator->expects($this->once())
- ->method('generateFromUrl')
+ ->method('generate')
->with('Test title', $url)
->will($this->returnValue('link_html_string'));
$this->setMockContainerService('link_generator', $generator);
diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityLinkTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityLinkTest.php
index bb29ca8..361a7ea 100644
--- a/core/tests/Drupal/Tests/Core/Entity/EntityLinkTest.php
+++ b/core/tests/Drupal/Tests/Core/Entity/EntityLinkTest.php
@@ -8,7 +8,7 @@
namespace Drupal\Tests\Core\Entity;
use Drupal\Core\DependencyInjection\ContainerBuilder;
-use Drupal\Core\Url;
+use Drupal\Core\Link;
use Drupal\Tests\UnitTestCase;
/**
@@ -82,14 +82,16 @@ public function testLink($entity_label, $link_text, $expected_text, $link_rel =
$entity_type_id
]);
- $expected_url = new Url($route_name,
+ $expected_link = Link::createFromRoute(
+ $expected_text,
+ $route_name,
[$entity_type_id => $entity_id],
['entity_type' => $entity_type_id, 'entity' => $entity] + $link_options
- );
+ )->setLinkGenerator($this->linkGenerator);
$this->linkGenerator->expects($this->once())
- ->method('generateFromUrl')
- ->with($expected_text, $expected_url)
+ ->method('generateFromLink')
+ ->with($this->equalTo($expected_link))
->willReturn($expected);
$this->assertSame($expected, $entity->link($link_text, $link_rel, $link_options));
diff --git a/core/tests/Drupal/Tests/Core/Utility/LinkGeneratorTest.php b/core/tests/Drupal/Tests/Core/Utility/LinkGeneratorTest.php
index 061d282..7093fbf 100644
--- a/core/tests/Drupal/Tests/Core/Utility/LinkGeneratorTest.php
+++ b/core/tests/Drupal/Tests/Core/Utility/LinkGeneratorTest.php
@@ -84,7 +84,7 @@ public function providerTestGenerateHrefs() {
/**
* Tests the link method with certain hrefs.
*
- * @see \Drupal\Core\Utility\LinkGenerator::generateFromUrl()
+ * @see \Drupal\Core\Utility\LinkGenerator::generate()
* @see \Drupal\Tests\Core\Utility\LinkGeneratorTest::providerTestGenerate()
*
* @dataProvider providerTestGenerateHrefs
@@ -100,7 +100,7 @@ public function testGenerateHrefs($route_name, array $parameters, $absolute, $ex
$url = new Url($route_name, $parameters, array('absolute' => $absolute));
$url->setUrlGenerator($this->urlGenerator);
- $result = $this->linkGenerator->generateFromUrl('Test', $url);
+ $result = $this->linkGenerator->generate('Test', $url);
$this->assertTag(array(
'tag' => 'a',
'attributes' => array('href' => $expected_url),
@@ -108,11 +108,11 @@ public function testGenerateHrefs($route_name, array $parameters, $absolute, $ex
}
/**
- * Tests the generateFromUrl() method with a route.
+ * Tests the generate() method with a route.
*
- * @covers ::generateFromUrl()
+ * @covers ::generate()
*/
- public function testGenerateFromUrl() {
+ public function testGenerate() {
$this->urlGenerator->expects($this->once())
->method('generateFromRoute')
->with('test_route_1', array(), array('fragment' => 'the-fragment') + $this->defaultOptions)
@@ -125,7 +125,7 @@ public function testGenerateFromUrl() {
$url = new Url('test_route_1', array(), array('fragment' => 'the-fragment'));
$url->setUrlGenerator($this->urlGenerator);
- $result = $this->linkGenerator->generateFromUrl('Test', $url);
+ $result = $this->linkGenerator->generate('Test', $url);
$this->assertTag(array(
'tag' => 'a',
'attributes' => array(
@@ -136,14 +136,14 @@ public function testGenerateFromUrl() {
}
/**
- * Tests the generateFromUrl() method with an external URL.
+ * Tests the generate() method with an external URL.
*
* The set_active_class option is set to TRUE to ensure this does not cause
* an error together with an external URL.
*
- * @covers ::generateFromUrl()
+ * @covers ::generate()
*/
- public function testGenerateFromUrlExternal() {
+ public function testGenerateExternal() {
$this->urlGenerator->expects($this->once())
->method('generateFromPath')
->with('http://drupal.org', array('set_active_class' => TRUE, 'external' => TRUE) + $this->defaultOptions)
@@ -157,7 +157,7 @@ public function testGenerateFromUrlExternal() {
$url->setUrlGenerator($this->urlGenerator);
$url->setOption('set_active_class', TRUE);
- $result = $this->linkGenerator->generateFromUrl('Drupal', $url);
+ $result = $this->linkGenerator->generate('Drupal', $url);
$this->assertTag(array(
'tag' => 'a',
'attributes' => array(
@@ -170,7 +170,7 @@ public function testGenerateFromUrlExternal() {
/**
* Tests the link method with additional attributes.
*
- * @see \Drupal\Core\Utility\LinkGenerator::generateFromUrl()
+ * @see \Drupal\Core\Utility\LinkGenerator::generate()
*/
public function testGenerateAttributes() {
$this->urlGenerator->expects($this->once())
@@ -185,7 +185,7 @@ public function testGenerateAttributes() {
'attributes' => array('title' => 'Tooltip'),
));
$url->setUrlGenerator($this->urlGenerator);
- $result = $this->linkGenerator->generateFromUrl('Test', $url);
+ $result = $this->linkGenerator->generate('Test', $url);
$this->assertTag(array(
'tag' => 'a',
'attributes' => array(
@@ -198,7 +198,7 @@ public function testGenerateAttributes() {
/**
* Tests the link method with passed query options.
*
- * @see \Drupal\Core\Utility\LinkGenerator::generateFromUrl()
+ * @see \Drupal\Core\Utility\LinkGenerator::generate()
*/
public function testGenerateQuery() {
$this->urlGenerator->expects($this->once())
@@ -212,7 +212,7 @@ public function testGenerateQuery() {
'query' => array('test' => 'value'),
));
$url->setUrlGenerator($this->urlGenerator);
- $result = $this->linkGenerator->generateFromUrl('Test', $url);
+ $result = $this->linkGenerator->generate('Test', $url);
$this->assertTag(array(
'tag' => 'a',
'attributes' => array(
@@ -224,7 +224,7 @@ public function testGenerateQuery() {
/**
* Tests the link method with passed query options via parameters.
*
- * @see \Drupal\Core\Utility\LinkGenerator::generateFromUrl()
+ * @see \Drupal\Core\Utility\LinkGenerator::generate()
*/
public function testGenerateParametersAsQuery() {
$this->urlGenerator->expects($this->once())
@@ -236,7 +236,7 @@ public function testGenerateParametersAsQuery() {
$url = new Url('test_route_1', array('test' => 'value'), array());
$url->setUrlGenerator($this->urlGenerator);
- $result = $this->linkGenerator->generateFromUrl('Test', $url);
+ $result = $this->linkGenerator->generate('Test', $url);
$this->assertTag(array(
'tag' => 'a',
'attributes' => array(
@@ -248,7 +248,7 @@ public function testGenerateParametersAsQuery() {
/**
* Tests the link method with arbitrary passed options.
*
- * @see \Drupal\Core\Utility\LinkGenerator::generateFromUrl()
+ * @see \Drupal\Core\Utility\LinkGenerator::generate()
*/
public function testGenerateOptions() {
$this->urlGenerator->expects($this->once())
@@ -262,7 +262,7 @@ public function testGenerateOptions() {
'key' => 'value',
));
$url->setUrlGenerator($this->urlGenerator);
- $result = $this->linkGenerator->generateFromUrl('Test', $url);
+ $result = $this->linkGenerator->generate('Test', $url);
$this->assertTag(array(
'tag' => 'a',
'attributes' => array(
@@ -274,7 +274,7 @@ public function testGenerateOptions() {
/**
* Tests the link method with a script tab.
*
- * @see \Drupal\Core\Utility\LinkGenerator::generateFromUrl()
+ * @see \Drupal\Core\Utility\LinkGenerator::generate()
*/
public function testGenerateXss() {
$this->urlGenerator->expects($this->once())
@@ -287,7 +287,7 @@ public function testGenerateXss() {
// Test that HTML link text is escaped by default.
$url = new Url('test_route_4');
$url->setUrlGenerator($this->urlGenerator);
- $result = $this->linkGenerator->generateFromUrl("", $url);
+ $result = $this->linkGenerator->generate("", $url);
$this->assertNotTag(array(
'tag' => 'a',
'attributes' => array('href' => '/test-route-4'),
@@ -300,7 +300,7 @@ public function testGenerateXss() {
/**
* Tests the link method with html.
*
- * @see \Drupal\Core\Utility\LinkGenerator::generateFromUrl()
+ * @see \Drupal\Core\Utility\LinkGenerator::generate()
*/
public function testGenerateWithHtml() {
$this->urlGenerator->expects($this->at(0))
@@ -321,7 +321,7 @@ public function testGenerateWithHtml() {
'attributes' => array('title' => 'HTML Tooltip'),
));
$url->setUrlGenerator($this->urlGenerator);
- $result = $this->linkGenerator->generateFromUrl('Test', $url);
+ $result = $this->linkGenerator->generate('Test', $url);
$this->assertTag(array(
'tag' => 'a',
'attributes' => array(
@@ -333,7 +333,7 @@ public function testGenerateWithHtml() {
// Test that the 'html' option allows unsanitized HTML link text.
$url = new Url('test_route_5', array(), array('html' => TRUE));
$url->setUrlGenerator($this->urlGenerator);
- $result = $this->linkGenerator->generateFromUrl('HTML output', $url);
+ $result = $this->linkGenerator->generate('HTML output', $url);
$this->assertTag(array(
'tag' => 'a',
'attributes' => array('href' => '/test-route-5'),
@@ -346,7 +346,7 @@ public function testGenerateWithHtml() {
/**
* Tests the active class on the link method.
*
- * @see \Drupal\Core\Utility\LinkGenerator::generateFromUrl()
+ * @see \Drupal\Core\Utility\LinkGenerator::generate()
*
* @todo Test that the active class is added on the front page when generating
* links to the front page when drupal_is_front_page() is converted to a
@@ -375,7 +375,7 @@ public function testGenerateActive() {
// Render a link.
$url = new Url('test_route_1', array(), array('set_active_class' => TRUE));
$url->setUrlGenerator($this->urlGenerator);
- $result = $this->linkGenerator->generateFromUrl('Test', $url);
+ $result = $this->linkGenerator->generate('Test', $url);
$this->assertTag(array(
'tag' => 'a',
'attributes' => array('data-drupal-link-system-path' => 'test-route-1'),
@@ -384,7 +384,7 @@ public function testGenerateActive() {
// Render a link with the set_active_class option disabled.
$url = new Url('test_route_1', array(), array('set_active_class' => FALSE));
$url->setUrlGenerator($this->urlGenerator);
- $result = $this->linkGenerator->generateFromUrl('Test', $url);
+ $result = $this->linkGenerator->generate('Test', $url);
$this->assertNotTag(array(
'tag' => 'a',
'attributes' => array('data-drupal-link-system-path' => 'test-route-1'),
@@ -396,7 +396,7 @@ public function testGenerateActive() {
'set_active_class' => TRUE,
));
$url->setUrlGenerator($this->urlGenerator);
- $result = $this->linkGenerator->generateFromUrl('Test', $url);
+ $result = $this->linkGenerator->generate('Test', $url);
$this->assertTag(array(
'tag' => 'a',
'attributes' => array(
@@ -411,7 +411,7 @@ public function testGenerateActive() {
'set_active_class' => TRUE,
));
$url->setUrlGenerator($this->urlGenerator);
- $result = $this->linkGenerator->generateFromUrl('Test', $url);
+ $result = $this->linkGenerator->generate('Test', $url);
$this->assertTag(array(
'tag' => 'a',
'attributes' => array(
@@ -426,7 +426,7 @@ public function testGenerateActive() {
'set_active_class' => TRUE,
));
$url->setUrlGenerator($this->urlGenerator);
- $result = $this->linkGenerator->generateFromUrl('Test', $url);
+ $result = $this->linkGenerator->generate('Test', $url);
$this->assertTag(array(
'tag' => 'a',
'attributes' => array(