function Link::toString

Same name in other branches
  1. 9 core/lib/Drupal/Core/Link.php \Drupal\Core\Link::toString()
  2. 8.9.x core/lib/Drupal/Core/Link.php \Drupal\Core\Link::toString()
  3. 11.x core/lib/Drupal/Core/Link.php \Drupal\Core\Link::toString()

Generates the HTML for this Link object.

Do not use this method to render a link in an HTML context. In an HTML context, self::toRenderable() should be used so that render cache information is maintained. However, there might be use cases such as tests and non-HTML contexts where calling this method directly makes sense.

Return value

\Drupal\Core\GeneratedLink The link HTML markup.

See also

\Drupal\Core\Link::toRenderable()

File

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

Class

Link
Defines an object that holds information about a link.

Namespace

Drupal\Core

Code

public function toString() {
    return $this->getLinkGenerator()
        ->generate($this->text, $this->url);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.