You are here

class Link in Zircon Profile 8

Same name in this branch
  1. 8 vendor/symfony/dom-crawler/Link.php \Symfony\Component\DomCrawler\Link
  2. 8 core/lib/Drupal/Core/Link.php \Drupal\Core\Link
  3. 8 core/lib/Drupal/Core/Render/Element/Link.php \Drupal\Core\Render\Element\Link
Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Link.php \Drupal\Core\Link

Defines an object that holds information about a link.

Hierarchy

Expanded class hierarchy of Link

24 files declare their use of Link
BookBreadcrumbBuilder.php in core/modules/book/src/BookBreadcrumbBuilder.php
Contains \Drupal\book\BookBreadcrumbBuilder.
Breadcrumb.php in core/lib/Drupal/Core/Breadcrumb/Breadcrumb.php
Contains \Drupal\Core\Breadcrumb\Breadcrumb.
BreadcrumbTest.php in core/tests/Drupal/Tests/Core/Breadcrumb/BreadcrumbTest.php
Contains \Drupal\Tests\Core\Breadcrumb\BreadcrumbTest.
CommentBreadcrumbBuilder.php in core/modules/comment/src/CommentBreadcrumbBuilder.php
Contains \Drupal\comment\CommentBreadcrumbBuilder.
Entity.php in core/lib/Drupal/Core/Entity/Entity.php
Contains \Drupal\Core\Entity\Entity.

... See full list

11 string references to 'Link'
contextual.views.schema.yml in core/modules/contextual/config/schema/contextual.views.schema.yml
core/modules/contextual/config/schema/contextual.views.schema.yml
DrupalLink::getButtons in core/modules/ckeditor/src/Plugin/CKEditorPlugin/DrupalLink.php
Returns the buttons that this plugin provides, along with metadata.
FieldHelpTest::testFieldHelp in core/modules/field/src/Tests/FieldHelpTest.php
Test the Field module's help page.
HtmlResponseAttachmentsProcessor::processHtmlHeadLink in core/lib/Drupal/Core/Render/HtmlResponseAttachmentsProcessor.php
Transform a html_head_link array into html_head and http_header arrays.
link.info.yml in core/modules/link/link.info.yml
core/modules/link/link.info.yml

... See full list

File

core/lib/Drupal/Core/Link.php, line 16
Contains \Drupal\Core\Link.

Namespace

Drupal\Core
View source
class Link implements RenderableInterface {

  /**
   * @deprecated in Drupal 8.0.x-dev, will be removed before Drupal 9.0.0.
   */
  use LinkGeneratorTrait;

  /**
   * The text of the link.
   *
   * @var string
   */
  protected $text;

  /**
   * The URL of the link.
   *
   * @var \Drupal\Core\Url
   */
  protected $url;

  /**
   * Constructs a new Link object.
   *
   * @param string $text
   *   The text of the link.
   * @param \Drupal\Core\Url $url
   *   The url object.
   */
  public function __construct($text, Url $url) {
    $this->text = $text;
    $this->url = $url;
  }

  /**
   * Creates a Link object from a given route name and parameters.
   *
   * @param string $text
   *   The text of the link.
   * @param string $route_name
   *   The name of the route
   * @param array $route_parameters
   *   (optional) An associative array of parameter names and values.
   * @param array $options
   *   (optional) An associative array of additional options, with the following
   *   elements:
   *   - 'query': An array of query key/value-pairs (without any URL-encoding)
   *     to append to the URL. Merged with the parameters array.
   *   - 'fragment': A fragment identifier (named anchor) to append to the URL.
   *     Do not include the leading '#' character.
   *   - 'absolute': Defaults to FALSE. Whether to force the output to be an
   *     absolute link (beginning with http:). Useful for links that will be
   *     displayed outside the site, such as in an RSS feed.
   *   - 'language': An optional language object used to look up the alias
   *     for the URL. If $options['language'] is omitted, it defaults to the
   *     current language for the language type LanguageInterface::TYPE_URL.
   *   - 'https': Whether this URL should point to a secure location. If not
   *     defined, the current scheme is used, so the user stays on HTTP or HTTPS
   *     respectively. TRUE enforces HTTPS and FALSE enforces HTTP.
   *
   * @return static
   */
  public static function createFromRoute($text, $route_name, $route_parameters = array(), $options = array()) {
    return new static($text, new Url($route_name, $route_parameters, $options));
  }

  /**
   * Creates a Link object from a given Url object.
   *
   * @param string $text
   *   The text of the link.
   * @param \Drupal\Core\Url $url
   *   The Url to create the link for.
   *
   * @return static
   */
  public static function fromTextAndUrl($text, Url $url) {
    return new static($text, $url);
  }

  /**
   * Returns the text of the link.
   *
   * @return string
   */
  public function getText() {
    return $this->text;
  }

  /**
   * Sets the new text of the link.
   *
   * @param string $text
   *   The new text.
   *
   * @return $this
   */
  public function setText($text) {
    $this->text = $text;
    return $this;
  }

  /**
   * Returns the URL of the link.
   *
   * @return \Drupal\Core\Url
   */
  public function getUrl() {
    return $this->url;
  }

  /**
   * Sets the URL of this link.
   *
   * @param Url $url
   *   The URL object to set
   *
   * @return $this
   */
  public function setUrl(Url $url) {
    $this->url = $url;
    return $this;
  }

  /**
   * Generates the HTML for this Link object.
   *
   * @return \Drupal\Core\GeneratedLink
   *   The link HTML markup.
   *
   * @deprecated in Drupal 8.0.x-dev, will be removed before Drupal 9.0.0. Use
   *   self::toRenderable() instead.
   */
  public function toString() {
    return $this
      ->getLinkGenerator()
      ->generateFromLink($this);
  }

  /**
   * {@inheritdoc}
   */
  public function toRenderable() {
    return [
      '#type' => 'link',
      '#url' => $this->url,
      '#title' => $this->text,
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Link::$text protected property The text of the link.
Link::$url protected property The URL of the link.
Link::createFromRoute public static function Creates a Link object from a given route name and parameters.
Link::fromTextAndUrl public static function Creates a Link object from a given Url object.
Link::getText public function Returns the text of the link.
Link::getUrl public function Returns the URL of the link.
Link::setText public function Sets the new text of the link.
Link::setUrl public function Sets the URL of this link.
Link::toRenderable public function Returns a render array representation of the object. Overrides RenderableInterface::toRenderable
Link::toString Deprecated public function Generates the HTML for this Link object.
Link::__construct public function Constructs a new Link object.
LinkGeneratorTrait::$linkGenerator protected property The link generator. 1
LinkGeneratorTrait::getLinkGenerator protected function Returns the link generator.
LinkGeneratorTrait::l protected function Renders a link to a route given a route name and its parameters.
LinkGeneratorTrait::setLinkGenerator public function Sets the link generator service.