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')
];

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

snufkin created an issue. See original summary.

snufkin’s picture

Rene Bakx’s picture

Status: Needs review » Reviewed & tested by the community

This 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.

Anonymous’s picture

Experienced this when Twig got updated recently.

The patch fixes the fatal error on the user login page.

  • snufkin committed f308c6c on 8.x-3.x
    Issue #2861948 by snufkin: Incorrect usage of #markup and the Link...
snufkin’s picture

Priority: Normal » Critical
Status: Reviewed & tested by the community » Fixed

Fixed, new stable will be out shortly, as this is a critical bug.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.