Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
A recent deprecation fix introduced in #2859215 causes an issue, as the Link object is passed to the form builders #markup element, triggering the following error:
The website encountered an unexpected error. Please try again later.
Recoverable fatal error: Object of class Drupal\Core\Link could not be converted to string in Drupal\Component\Utility\Xss::filter() (line 67 of core/lib/Drupal/Component/Utility/Xss.php).
Instead of using #markup and Link I think we should be using the link element type (https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Render%21...)
$build['examples_link'] = [
'#title' => $this->t('Examples'),
'#type' => 'link',
'#url' => Url::fromRoute('examples.description')
];
Comments
Comment #2
snufkin CreditAttribution: snufkin at Cheppers commentedInitial patch converting the implementation to use the link element.
Comment #3
Rene BakxThis patch indeed removes the " Recoverable fatal error: Object of class Drupal\Core\Link could not be converted to string". And since this is untested code, I believe it's commit worthy.
Comment #4
Anonymous (not verified) CreditAttribution: Anonymous commentedExperienced this when Twig got updated recently.
The patch fixes the fatal error on the user login page.
Comment #6
snufkin CreditAttribution: snufkin as a volunteer commentedFixed, new stable will be out shortly, as this is a critical bug.