Problem/Motivation

  1. l() does not need a $label argument. Label can default to $path.
  2. HTML attributes should not be in the $options parameter, unnecessarily passed through url($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

  1. Switch position of first and second arguments.
  2. Handle HTML attributes in new $attributes parameter.

Remaining tasks

Agreement.
Passing tests.

User interface changes

None.

API changes

Proposed function signature:

  function l($path = NULL, $label = $path, $options = array(), $attributes = array()) {}
  1. Path first. Default to <front>. Simplest usage: l('/node/3');
  2. Label optional. Default to 'path'. No more l($path, $path);. I actually want to call this variable 'content' or maybe 'label'.
  3. Options. Third argument $options (in same position as before), now only used for url and filter options such as query, fragment, and html, and absolute.
  4. 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 through url().

#1825820: theme('link')

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

robloach’s picture

Component: usability » base system

sub

marcingy’s picture

Version: 7.x-dev » 8.x-dev
droplet’s picture

oh. I didn't notice it before.
sub

steveoliver’s picture

Interesting 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())

steveoliver’s picture

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

steveoliver’s picture

Assigned: Unassigned » steveoliver

Assigning this to myself. Rolling a patch against HEAD...

steveoliver’s picture

Status: Active » Needs review
StatusFileSize
new127.03 KB

Let's see what testbot has to say.

Status: Needs review » Needs work

The last submitted patch, drupal-l_function_parameters_order-270933-7.patch, failed testing.

steveoliver’s picture

Issue summary: View changes

Update with Issue Summary Template

steveoliver’s picture

Issue summary: View changes

Closing

steveoliver’s picture

Issue summary: View changes

grammar after url()

steveoliver’s picture

New 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'.

steveoliver’s picture

Title: l function - order of params » l function - order of params + attributes

changing title.

Status: Needs review » Needs work

The last submitted patch, drupal-l_function_parameters_order-270933-9.patch, failed testing.

steveoliver’s picture

Should be a few less comment related test fails, and a few less undefined index 'attributes' errors.

Status: Needs review » Needs work
Issue tags: -link functions and templates

The last submitted patch, drupal-l_function_parameters_order-270933-12.patch, failed testing.

Anonymous’s picture

Issue summary: View changes

Add note about theming and link to related issue. Update grammar about attributes.

jibran’s picture

Issue summary: View changes

Updated issue summary.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Assigned: steveoliver » Unassigned
Status: Needs work » Closed (outdated)

The l function was deprecated and removed. I am closing this as outdated.

#2606376: mark \Drupal::l() as deprecated