Problem/Motivation
l()does not need a$labelargument. Label can default to$path.- HTML attributes should not be in the
$optionsparameter, unnecessarily passed throughurl($path, $options)during processing and akwardly nested in$variables['options']['attributes']during theming*1.
Notes:
1 #1778610: Remove the check for a link template from l(), have l() always output just a string.
Proposed resolution
- Switch position of first and second arguments.
- Handle HTML attributes in new
$attributesparameter.
Remaining tasks
Agreement.
Passing tests.
User interface changes
None.
API changes
Proposed function signature:
function l($path = NULL, $label = $path, $options = array(), $attributes = array()) {}
- Path first. Default to
<front>. Simplest usage:l('/node/3'); - Label optional. Default to 'path'. No more
l($path, $path);. I actually want to call this variable 'content' or maybe 'label'. - Options. Third argument
$options(in same position as before), now only used for url and filter options such asquery,fragment, andhtml, andabsolute. - Attributes Fourth argument
$attributes(new parameter), only for actual HTML attributes. No more$variables['options']['attributes']for themers and no more$options['attributes']being passed unnecessarily throughurl().
Related Issues
Original report by danielb
I was sitting here thinking about the l() function. Why does it take it's parameters in the order 1) text to display 2) path ?
It seems to me the l function needs only ONE argument and that is path.
It does not need a text to display argument at all, because the minimum required to produce a hyperlink is the path. The hyperlink can use the path both for the URL to link to AND the words to use to link to there. You could write a quick link like so: l('node/3') just as quickly as you can do drupal_goto('node/3')
Of course the second argument could be used to override the display text: l('node/3', "Node Three")
function l($path, $text = $path, $options = array())
Many people already use the l() function by supplying the 'path' for both the first two arguments, and seem to be happy about it, but I think it makes more sense the way I explained.
Comments
Comment #1
robloachsub
Comment #2
marcingy commentedComment #3
droplet commentedoh. I didn't notice it before.
sub
Comment #4
steveoliver commentedInteresting thought -- so the path would be used as a default 'text' if 'text' is not supplied..
Also, I've considered whether we should call 'text' "content" as a link isn't always text -- it can be other markup such as an image.
Lastly, and I think I'll open a separate issue for this is, 'attributes' need to be removed from the 'options' array, to become its own new fourth argument.
Thus, the function signature would become
function l($path, $content = NULL, $options = array(), $attributes = array())Comment #5
steveoliver commentedA possible repercussion (likely down the road) would be that, given *only* the first argument 'path', we could possibly dynamically lookup and use the "title" of that path, whether in routes or pages or whatever...
Comment #6
steveoliver commentedAssigning this to myself. Rolling a patch against HEAD...
Comment #7
steveoliver commentedLet's see what testbot has to say.
Comment #8.0
steveoliver commentedUpdate with Issue Summary Template
Comment #8.1
steveoliver commentedClosing
Comment #8.2
steveoliver commentedgrammar after url()
Comment #9
steveoliver commentedNew patch + interdiff of 7-9.
Should fix at least a few tests (comment.module).
Handling of defaults as described in the issue summary (also recently updated).
DocBlock for $attributes.
There may be missing conversions of theme('link') implemenatations to account for change in parameter name 'text' to 'content'.
Comment #10
steveoliver commentedchanging title.
Comment #12
steveoliver commentedShould be a few less comment related test fails, and a few less undefined index 'attributes' errors.
Comment #13.0
(not verified) commentedAdd note about theming and link to related issue. Update grammar about attributes.
Comment #13.1
jibranUpdated issue summary.
Comment #27
quietone commentedThe l function was deprecated and removed. I am closing this as outdated.
#2606376: mark \Drupal::l() as deprecated