Render a link from a FieldPluginBase I created a custom view field with the hook _views_data and a custom Class who extends FieldPluginBase.

With the render method, I can return a sample string :

class MyCustomClassViewsField extends FieldPluginBase {
...
    public function render(ResultRow $values) {
      $node = $values-&gt;_entity;
      return $node-&gt;id(); // My view field shows the nid of the current node
    }
...


Now, I want shows a link with my field. I tried : 

class MyCustomClassViewsField extends FieldPluginBase {
...
    public function render(ResultRow $values) {
      $node = $values-&gt;_entity;
      return "&lt;a href='http://www.test.com'&gt;custom link&lt;/a&gt;"
    }
...


But my field in my view shows : 

&lt;a href='http://www.test.com'&gt;custom link&lt;/a&gt;


and not 

custom link

How can I show the link as an html element, not a sample text ? 

Thank you =)

UP

This code work : 

return array('#markup' =&gt; \Drupal::l("test",\Drupal\Core\Url::fromUri("http://www.example.com")));


ut the l() function is deprecated. If I use Link::fromTextAndUrl instead : 

return array('#markup' =&gt; \Drupal\Core\Link::fromTextAndUrl("test",\Drupal\Core\Url::fromUri("http://www.example.com")));


I get the error : 


  [Sun Sep 18 22:17:59.444188 2016] [:error] [pid 2143] [client
  192.168.1.48:53322] Recoverable fatal error: Object of class Drupal\Core\Link could not be converted to string in
  /var/www/xxxxx/core/lib/Drupal/Component/Utility/Xss.php
  on line 67, referer:
  https://192.168.1.45/admin/structure/views/view/customview
  
  [Sun Sep 18 22:17:59.446098 2016] [:error] [pid 2143] [client
  192.168.1.48:53322] PHP Fatal error:  Uncaught Error: Call to a member function get() on null in
  /var/www/xxxxx/core/lib/Drupal/Core/Session/SessionHandler.php:76\nStack
  trace:\n#0
  /var/www/xxxxx/vendor/symfony/http-foundation/Session/Storage/Handler/WriteCheckSessionHandler.php(89):
  Drupal\Core\Session\SessionHandler->write('BTaHaVF0t-bMk2Z...',
  '_sf2_attributes...')\n#1
  /var/www/xxxxx/core/lib/Drupal/Core/Session/WriteSafeSessionHandler.php(75):
  Symfony\Component\HttpFoundation\Session\Storage\Handler\WriteCheckSessionHandler->write('BTaHaVF0t-bMk2Z...',
  '_sf2_attributes...')\n#2
  /var/www/xxxxx/vendor/symfony/http-foundation/Session/Storage/Proxy/SessionHandlerProxy.php(77):
  Drupal\Core\Session\WriteSafeSessionHandler->write('BTaHaVF0t-bMk2Z...',
  '_sf2_attributes...')\n#3 [internal function]:
  Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy->write('BTaHaVF0t-bMk2Z...',
  '_sf2_attributes...')\n#4 [internal function]:
  session_write_close()\n#5 {main}\n  thrown in
  /var/www/xxxxx/core/lib/Drupal/Core/Session/SessionHandler.php
  on line 76, referer:
  https://1xxxxx/admin/structure/views/view/customview


How can I replace the l deprecated function ?
You need to convert array to string to show it as link. May this works for you.

class MyCustomClassViewsField extends FieldPluginBase {
...
    public function render(ResultRow $values) {
      $node = $values-&gt;_entity;
$title = 'Custom Link';
$url = \Drupal\Core\Url::fromUri('http://www.test.com');
$link = \Drupal\Core\Link::fromTextAndUrl($title, $url)-&gt;toString();

      return $link;
    }