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

Creates a Link object from a given route name and 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


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

... See full list


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


Defines an object that holds information about a link.




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


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>

badshah007’s picture

I am new in drupal and now I have to make a link in a form page (A sign up link in sign in page ) . So can you tell me how can I use this api and make the link in the form. Or rather I should use "a href" in .html.twig file? Because I did that but it's not making a sense. Please help me.. Thanks