By thedavidmeister on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.x
Issue links:
Description:
Summary:
- theme_link has been removed from core in order to improve rendering performance and because it no longer provides any benefits over calling l() directly.
- The attributes '#text' and '#path' have been changed to '#title' and '#href' respectively in order to provide consistent attribute naming throughout the Render API and Form API.
- Themers should replace '#theme' => 'link' with '#type' => 'link' in any render arrays, while also changing '#text' to '#title' and '#path' to '#href'.
- An '#options' attribute can be specified that will be passed to l() (and url() internally within l()) to specify extra options for the link such as query parameters, HTML attributes, etc.
- See #1985470-10: Remove theme_link() for the reasoning behind this change.
- Themers should replace any hook_preprocess_link() implementations with a hook_link_alter() implementation. hook_link_alter() was added in #1922454: Gut l(), fix theme('link'), have a working framework for consistently generated links inside and outside of Twig.
Code example:
Before (D7):
$link_array = array(
'#theme' => 'link',
'#text' => 'The text to render inside the <a> tag',
'#path' => 'http://www.example.com/',
);
drupal_render($link_array);
After (D8):
$link_array = array(
'#type' => 'link',
'#title' => 'The text to render inside the <a> tag',
'#url' => Url::fromUri('http://www.example.com/'),
);
drupal_render($link_array);
For additional examples demonstrating usage of both '#options' and hook_link_alter(), please reference https://drupal.org/node/1819788.
Impacts:
Module developers
Themers