Question
How to create a link on Drupal 8, like l() and url() on Drupal 7 ?
Exemple:
use Drupal\Core\Url;
// Internal path (defined by a route in Drupal 8).
$url = Url::fromRoute('help.page.views');
$internal_link = \Drupal::l(t('Views Help Page'), $url);
// External Uri.
$url = Url::fromUri('http://www.example.com/');
$external_link = \Drupal::l(t('External link'), $url);
Update:
The l() function \Drupal::l() is deprecated.
Use \Drupal\Core\Link instead
Example:
use \Drupal\Core\Link;
$link = Link::fromTextAndUrl($text, $url);
#OR
$link = \Drupal\Core\Link::fromTextAndUrl($text, $url);
Comments