diff --git a/core/lib/Drupal/Core/Link.php b/core/lib/Drupal/Core/Link.php index 3d47a9ae00f..91718a687c9 100644 --- a/core/lib/Drupal/Core/Link.php +++ b/core/lib/Drupal/Core/Link.php @@ -18,9 +18,12 @@ class Link implements RenderableInterface { protected $linkGenerator; /** - * The text of the link. - * - * @var string + * The link text for the anchor tag as a translated string or render array. + * Strings will be sanitized automatically. If you need to output HTML in + * the link text, use a render array or an already sanitized string such as + * the output of \Drupal\Component\Utility\Xss::filter() or + * \Drupal\Component\Render\FormattableMarkup. + * @var string|array|\Drupal\Component\Render\MarkupInterface */ protected $text; @@ -34,8 +37,12 @@ class Link implements RenderableInterface { /** * Constructs a new Link object. * - * @param string $text - * The text of the link. + * @param string|array|\Drupal\Component\Render\MarkupInterface $text + * The link text for the anchor tag as a translated string or render array. + * Strings will be sanitized automatically. If you need to output HTML in + * the link text, use a render array or an already sanitized string such as + * the output of \Drupal\Component\Utility\Xss::filter() or + * \Drupal\Component\Render\FormattableMarkup. * @param \Drupal\Core\Url $url * The url object. */ @@ -49,6 +56,10 @@ class Link implements RenderableInterface { * * @param string|array|\Drupal\Component\Render\MarkupInterface $text * The link text for the anchor tag as a translated string or render array. + * Strings will be sanitized automatically. If you need to output HTML in + * the link text, use a render array or an already sanitized string such as + * the output of \Drupal\Component\Utility\Xss::filter() or + * \Drupal\Component\Render\FormattableMarkup. * @param string $route_name * The name of the route * @param array $route_parameters @@ -66,8 +77,12 @@ class Link implements RenderableInterface { /** * Creates a Link object from a given Url object. * - * @param string $text - * The text of the link. + * @param string|array|\Drupal\Component\Render\MarkupInterface $text + * The link text for the anchor tag as a translated string or render array. + * Strings will be sanitized automatically. If you need to output HTML in + * the link text, use a render array or an already sanitized string such as + * the output of \Drupal\Component\Utility\Xss::filter() or + * \Drupal\Component\Render\FormattableMarkup. * @param \Drupal\Core\Url $url * The Url to create the link for. * @@ -80,7 +95,12 @@ class Link implements RenderableInterface { /** * Returns the text of the link. * - * @return string + * @return string|array|\Drupal\Component\Render\MarkupInterface + * The link text for the anchor tag as a translated string or render array. + * Strings will be sanitized automatically. If you need to output HTML in + * the link text, use a render array or an already sanitized string such as + * the output of \Drupal\Component\Utility\Xss::filter() or + * \Drupal\Component\Render\FormattableMarkup. */ public function getText() { return $this->text; @@ -89,8 +109,12 @@ class Link implements RenderableInterface { /** * Sets the new text of the link. * - * @param string $text - * The new text. + * @param string|array|\Drupal\Component\Render\MarkupInterface $text + * The link text for the anchor tag as a translated string or render array. + * Strings will be sanitized automatically. If you need to output HTML in + * the link text, use a render array or an already sanitized string such as + * the output of \Drupal\Component\Utility\Xss::filter() or + * \Drupal\Component\Render\FormattableMarkup. * * @return $this */