8.2.x Link.php public static Link::createFromRoute($text, $route_name, $route_parameters = array(), $options = array())
8.0.x Link.php public static Link::createFromRoute($text, $route_name, $route_parameters = array(), $options = array())
8.1.x Link.php public static Link::createFromRoute($text, $route_name, $route_parameters = array(), $options = array())
8.3.x Link.php public static Link::createFromRoute($text, $route_name, $route_parameters = [], $options = [])

Creates a Link object from a given route name and parameters.

Parameters

string $text: The text of the link.

string $route_name: The name of the route

array $route_parameters: (optional) An associative array of parameter names and values.

array $options: The options parameter takes exactly the same structure. See \Drupal\Core\Url::fromUri() for details.

Return value

static

21 calls to Link::createFromRoute()
BookBreadcrumbBuilder::build in core/modules/book/src/BookBreadcrumbBuilder.php
CommentBreadcrumbBuilder::build in core/modules/comment/src/CommentBreadcrumbBuilder.php
EntityController::addPage in core/lib/Drupal/Core/Entity/Controller/EntityController.php
Displays add links for the available bundles.
EntityLinkTest::testLink in core/tests/Drupal/Tests/Core/Entity/EntityLinkTest.php
Tests for the Entity::link() method
EntityLinkTest::testToLink in core/tests/Drupal/Tests/Core/Entity/EntityLinkTest.php
Tests for the Entity::toLink() method

... See full list

File

core/lib/Drupal/Core/Link.php, line 60

Class

Link
Defines an object that holds information about a link.

Namespace

Drupal\Core

Code

public static function createFromRoute($text, $route_name, $route_parameters = array(), $options = array()) {
  return new static($text, new Url($route_name, $route_parameters, $options));
}

Comments

akalata’s picture

Note: You can also use a "attributes" array within $options to provide classes, etc. similar to l() and Url(). A bug has been filed at https://www.drupal.org/node/2818011

leymannx’s picture

$options = ['absolute' => TRUE, 'attributes' => ['class' => 'this-class']];
$link_object = Drupal\Core\Link::createFromRoute($node_title, 'entity.node.canonical', ['node' => $nid], $options);

Will output <a href="http://example.com/path-to-my-node" class="this-class">My Node's Title</a>