Problem/Motivation

The current entity language API works with $entity->getTranslation() to ask for a translated version of the entity and NOT with methods providing access to translated versions individually. Once a translation is retrieved, the methods just work with the translated values. The langcode argument on label() was added in #1616952: Add a langcode parameter to EntityInterface::label() in a previous life of the entity language API and is pointless now. It does not even work for the base field on the entity, it does not consider that langcode to retrieve the label (it only passes it on to a title callback if present). The title callback however could use getLanguage() on the entity, no need to pass it on explicitly. That is part of the appeal of the new API.

Proposed resolution

Remove the pointless argument. The title callback gets the whole entity, so it can do getLanguage() if it needs the active language on the entity copy.

Remaining tasks

Commit.

User interface changes

None.

API changes

Entities will not have a langcode method on label.

Comments

Status: Needs review » Needs work

The last submitted patch, label-langcode-pointless.patch, failed testing.

gábor hojtsy’s picture

Title: ContentEntity label langcode argument is a lie » Entity label langcode argument is a lie, incompatible with current API
Status: Needs work » Needs review
StatusFileSize
new2.64 KB
new1.6 KB

It helps to update the interface and base Entity.php implementation :) The config entity base implementation does not even have the label method.

gábor hojtsy’s picture

StatusFileSize
new2.65 KB
new972 bytes

Looking at it more, the label() method on the content entity then is the same as the default Entity.php implementation, so pointless to have two copies of it.

plach’s picture

Status: Needs review » Reviewed & tested by the community

Makes totally sense. RTBC if green.

gábor hojtsy’s picture

StatusFileSize
new2.67 KB
new948 bytes

I was a bit trigger happy there :D The content entity has a fielditem as the label, so it needs to use ->value. That is the only difference from the base entity implementation. Sad, but true. :/

We could also theoretically just invoke the parent and then work on top of that. BUT then the parent method would return a field item list instead of a string, so it would not be true to its interface docs, and that would be a fail. So we need to have this code in content entity.

gábor hojtsy’s picture

Status: Reviewed & tested by the community » Needs review
gábor hojtsy’s picture

StatusFileSize
new6.47 KB
new3.8 KB

Also updating docs on label_callback and the only implementations I found of that in entity_test and user. The user one did not have a langcode anyway, but the code comment on that was *misguided*. It was missing a word *no* :D Also not really at the right place. Since it relies on the username method which will rely on multilingual base fields if available, this comment should go to the base field definition (and corrected there).

In the meantime k4v found implementations of label() with langcode in config entities. Looking forward to more updates on that :)

The last submitted patch, 2: label-langcode-pointless-2.patch, failed testing.

The last submitted patch, 3: label-langcode-pointless-3.patch, failed testing.

k4v’s picture

StatusFileSize
new10.33 KB
new3.86 KB

So here is a new patch with some more langcode parameters removed.

gábor hojtsy’s picture

The changes look good. Let's hope testbot is not going to act up.

The last submitted patch, 10: label-langcode-pointless-6.patch, failed testing.

k4v’s picture

The last submitted patch, 10: label-langcode-pointless-6.patch, failed testing.

k4v’s picture

StatusFileSize
new10.38 KB

lets see...

gábor hojtsy’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community
Issue tags: +API clean-up
Related issues: +#2142987: Multilingual node search bugs with title and language filtering

Back to RTBC as per #4, in person review with @fago and my review of the updates from k4v. Looks all good.

linl’s picture

linl’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new10.44 KB

Reroll, no longer applied.

The last submitted patch, 15: label-langcode-pointless-7.patch, failed testing.

The last submitted patch, 15: label-langcode-pointless-7.patch, failed testing.

gábor hojtsy’s picture

Status: Needs review » Reviewed & tested by the community

Looks good :)

gábor hojtsy’s picture

Issue tags: +Vienna2013
webchick’s picture

Title: Entity label langcode argument is a lie, incompatible with current API » Change notice: Entity label langcode argument is a lie, incompatible with current API
Category: Bug report » Task
Priority: Normal » Major
Status: Reviewed & tested by the community » Active
Issue tags: +Approved API change, +Needs change record

This looks like good clean-up. Tagging.

Committed and pushed to 8.x. Thanks!

This may need a change notice.

webchick’s picture

Title: Change notice: Entity label langcode argument is a lie, incompatible with current API » Entity label langcode argument is a lie, incompatible with current API
Priority: Major » Normal
Status: Active » Needs work
Issue tags: -Needs change record

Sigh. Spoke too soon. Patch no longer applies. >:\

I cannot over-emphasize how badly I want #2125269: [META] Regressions in issue queue workflow fixed.

gábor hojtsy’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new9.84 KB

Fascinating how many conflicts there may be for a patch sitting even for 2 days.

gábor hojtsy’s picture

linl’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new9.36 KB

Another reroll following #2155889: Remove Editor::label()

gábor hojtsy’s picture

Status: Needs review » Reviewed & tested by the community

Great reroll, thanks.

xjm’s picture

webchick’s picture

Status: Reviewed & tested by the community » Needs work

Sorry, this went stale with all the recent major entity refactoring.

plach’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new9.31 KB

Rerolled

webchick’s picture

Title: Entity label langcode argument is a lie, incompatible with current API » Change notice: Entity label langcode argument is a lie, incompatible with current API
Priority: Normal » Major
Status: Reviewed & tested by the community » Active
Issue tags: +Needs change record

Committed and pushed to 8.x. Thanks!

gábor hojtsy’s picture

Title: Change notice: Entity label langcode argument is a lie, incompatible with current API » Entity label langcode argument is a lie, incompatible with current API
Status: Active » Fixed
Issue tags: -sprint, -Needs change record

Added change notice at https://drupal.org/node/2166535. Also added to the more general change notice (https://drupal.org/node/2040323), but did not modify that change notice since it already properly explains how to get a translation and how to work with it. The label($langcode) problem was an intra-d8 problem that we introduced earlier in 8.x and now removed.

gábor hojtsy’s picture

Priority: Major » Normal

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.