Problem/Motivation
The $title variable in PathBasedBreadcrumbBuilder.php of system module could be returned as a render array, but new Link($title, $url) requires $title variable to be a string.
$title = $this->titleResolver->getTitle($route_request, $route_match->getRouteObject());
Returns for us a render array with #markup and #allowed_tags for a taxonomy term entity which is rendered via a custom taxonomy_term view instead of $title as a simple string.
I have this bug with Drupal core 8.7.11, but maybe it also occurs for newer releases. Maybe it is not only related to core, because we also use TVI contrib module and a lot of other stuff.
Steps to reproduce
Proposed resolution
Copy the documentation from \Drupal\Core\Utility\LinkGeneratorInterface::generate
* @param string|array|\Drupal\Component\Render\MarkupInterface $text
* The link text for the anchor tag as a translated string or render array.
* Strings will be sanitized automatically. If you need to output HTML in
* the link text, use a render array or an already sanitized string such as
* the output of \Drupal\Component\Utility\Xss::filter() or
* \Drupal\Component\Render\FormattableMarkup.
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Comment | File | Size | Author |
---|---|---|---|
#8 | 3163487-8.patch | 1.99 KB | raman.b |
#2 | drupal-system-breadcrumb-title_not_a_string_in_breadcrumb_builder-3163487-2.patch | 895 bytes | IT-Cru |
Issue fork drupal-3163487
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
IT-CruAdded my patch with my extra is_string check for $title variable.
Comment #3
IT-CruComment #5
idebr CreditAttribution: idebr at iO commentedLink can take an array as its title, because
\Drupal\Core\Utility\LinkGenerator::generate()
has the following code:The documentation for $text was updated in #2875807: Drupal::l() / Link::fromTextAndUrl $text documented as string, actually accepts string|array|\Drupal\Component\Render\MarkupInterface, but it seems we missed a spot since it still a string in the Link __construct method.
Comment #6
larowlanAre you saying this 'works as designed' @idebr and all we need to do is update docs?
Comment #7
idebr CreditAttribution: idebr at iO commented#6 Correct, Link can take an array as $text.
Comment #8
raman.b CreditAttribution: raman.b at OpenSense Labs commentedUpdating all the instances of
string $text
tostring|array|\Drupal\Component\Render\MarkupInterface $text
inDrupal\Core\Link
Comment #10
dawehnerI wonder whether it would be sensible to use exactly the same documentation as on the link generator, so the two places are in sync.
Comment #11
idebr CreditAttribution: idebr at iO commentedAgreed with #10, I updated the 'Proposed resolution' in the issue summary accordingly
Comment #14
sudiptadas19 CreditAttribution: sudiptadas19 at QED42 for Drupal India Association commentedAdded the documentation changes for Link class $text var. Available in MR403
Comment #15
JeroenTTest are failing because of:
Comment #16
sudiptadas19 CreditAttribution: sudiptadas19 at QED42 for Drupal India Association commented@JeroenT added a fix for the test failing. Please review.
Comment #18
guilhermevp CreditAttribution: guilhermevp at CI&T commentedPatch applies, works as proposed summary text. Moving to RTBC.
Comment #19
larowlanCommitted 0790536 and pushed to 9.3.x. Thanks!
Backported to 9.2.x