Parameter default for ConfigEntityBase::toUrl() is inconsistent with interface

Created on 27 November 2014, over 10 years ago
Updated 18 April 2025, 21 days ago

In \Drupal\Core\Entity\EntityInterface:

  public function urlInfo($rel = 'canonical', array $options = array());

In \Drupal\Core\Config\Entity\ConfigEntityBase (which implements that interface):

  public function urlInfo($rel = 'edit-form', array $options = []) {

This leads to retrieving the wrong URL when using the interface (even \Drupal\Core\Config\Entity\ConfigEntityInterface, of course) for type hinting, as there's no way to see the $rel parameter will be changed.

While this seems to be done on purpose for some reason (maybe some config entities don't have a canonical URL, or it often makes more sense to give the edit form as the default for them), in my opinion this is very bad DX, as it adds another inconsistency that a developer just has to know/remember, and with which an IDE cannot help. It's also bad programming style, I'd say – I was pretty amazed PHP even allows this construct, normally it's (thankfully) rather picky when it comes to implementing interfaces.

Anyways, I'd be very much in favor of changing this back to using the same default parameter everywhere, or even no default at all if the other really isn't possible.

The same applies to getSystemPath(), url() and link(), too, so all of these should be changed.

🐛 Bug report
Status

Closed: duplicate

Version

11.0 🔥

Component

entity system

Created by

🇦🇹Austria drunken monkey Vienna, Austria

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024