Problem/Motivation
Drupal::l($text, Url $url) and Drupal\Core\Link::fromTextAndUrl($text, Url $url) currently document $text as a string.
The function actually accepts string|array|\Drupal\Component\Render\MarkupInterface since it uses LinkGeneratorInterface::generate() to output markup.
This documentations is relevant when trying to create the following markup in a renderable array:
<a href="link" aria-label="See Picked Pens">
<svg>
<use xlink:href="#icon-codepen"></use>
</svg>
</a>
Source: https://css-tricks.com/accessible-svgs/
Proposed resolution
Update Drupal::l() and Drupal\Core\Link $text documentation so the $text input is correctly hinted.
Remaining tasks
- Write a patch
- Review
- Commit
User interface changes
None.
API changes
None.
Data model changes
None.
| Comment | File | Size | Author |
|---|---|---|---|
| #16 | 2875807-16.patch | 1.23 KB | idebr |
Comments
Comment #2
idebr commentedComment #6
idebr commentedAttached patch copies the
@paramdocumentation from\Drupal\Core\Utility\LinkGeneratorInterface::generate()to\Drupal\Core\Link::fromTextAndUrl()and\Drupal::l()Comment #10
kristen polNeeds updating for 9.1.x. Note that
l()was removed in 9.0.0:https://www.drupal.org/project/drupal/issues/2606376
Comment #11
hardik_patel_12 commentedUpdating @param documentation for Drupal\Core\Link::fromTextAndUrl() only for 9.1.x as l() was removed in 9.0.0. Kindly review a patch.
Comment #12
kristen polThanks for the update. I see that it addresses #10.
Looking at
LinkGeneratorInterface, it has this description:and the patch here has:
So it does not include this part:
but perhaps this is ok since it's documented in the
LinkGeneratorInterface.Given that and tests are green, marking this RTBC.
Comment #14
larowlanCommitted 1671837 and pushed to 9.1.x. Thanks!
Cherry-picked to 9.0.x
This needs updating for 8.9.x to make the same change to \Drupal::l() (which doesn't exist in 9.x)
Comment #16
idebr commentedAttached patch applies to 8.9.x and makes the same change to \Drupal::l()
Comment #17
kristen polThanks for the patch. Looks good to me.
1) Patch applies cleanly.
2) Tests pass.
3) Updates
Drupal::l()andLink::fromTextAndUrl()as expected and the text is identical in both places and matches what was used in 9.0.x/9.1.x.Comment #19
larowlanComment #20
larowlanC/p to 8.9.x - thanks