As the label should be translatable, we should add an optional langcode parameter to EntiyInterface::label(). As default, I'd suggest to go with the same handling as we do now for getters/setters, i.e. go with the default language of entities.
Having a better default language, let's say current interface or content language might be feasible here, but let's keep that out of this issue for now as it would involve respective fallback handling as well. Let's solve that in another issue, but just make sure we have a language-enabled EntiyInterface::label() for now.
Comments
Comment #1
fagoComment #2
webflo commentedComment #3
webflo commentedRelated issue: #1629924: Default return value from EntityInterface::label(), Entity::label(), entity_label() does not match
Comment #4
webflo commentedShould i add the $langcode parameter to 'user_label' too?
Comment #5
berdirI just RTBC'd #1616952: Add a langcode parameter to EntityInterface::label(), which removes/renames the entity_label() function, not sure if entity_page_label() needs the langcode as well. If not, we could simply remove it from this function and then they wouldn't conflict.
I guess this needs to be documented somewhere and the existing label callbacks, if we have any (?) should be updated.
Comment #6
berdirWrong reference, I of course meant #1615240: Remove entity_label() in favor of EntityInterface::label()
Comment #7
webflo commentedI think $langcode on entity_page_label() is still useful. Rerolled against 8.x HEAD after #1615240: Remove entity_label() in favor of EntityInterface::label() was committed.
Comment #8
berdirWe should document the additional argument to the label callback documentation in hook_entity_info() and update the user_label() and field_test_entity_label_callback().
Is there already an issue to remove entity type from the callback? If not then we should remove it. Or, can we somehow integrate a defaultLabel() method to the entity class, similar to 7.x contrib entity class. (Separate issue, of course).
Comment #9
webflo commentedAdding a $langcode to user_label() makes no sense because the username is not a multilingual property. Updated field_test_entity_label_callback() and documentation.
Comment #10
berdirHm, yes, but user_label() is a callback that receives a pre-defined list of arguments. IMHO the function definition should match to what it is called with. However, I don't want to decide that, who can we ask who can? :)
It looks like there is a lot of empty space on various lines. Should be able to group that differently, as we need to change it anyway, as it seems. E.g. "The langcode is optional" should fit on that line without going over 80 chars.
Comment #11
webflo commentedWe discussed the usage of user_label() at drupaldevdays. We (xjm, webchick, heyrocker, me) reached consensus that the username is not a multilingual property. The username is the visual identifier for a user and needs to be consistent in all languages. Therefor $langcode is not required.
Comment #12
berdirOk, looks good to go then. Not exactly sure what the "security reasons" comment exactly means.
I fully agree that the user name is not translatable. That wasn't my point. My point was only that this is a callback function, which receives a fixed set of arguments, and the function definition should reflect that. The implementation within is free to ignore the language of course. Doesn't matter much.
Comment #13
webchickSorry, by "security" I meant more "identity." Your username is the only way (in core anyway) to canonically identify YOUR comments/posts on the site to YOU. It's fully conceivable that Drupal.org has both a "sun" and a "sol" user. sun's comments should not get misattributed to sol when the user chooses Spanish as their language.
Comment #15
webflo commented#11: add-langcode-to-EntityInterface-label-1616952-11.patch queued for re-testing.
Comment #16
webflo commentedTest is green. Back to rtbc.
Comment #17
webchickLooks good! I just made a quick tweak to the docs to consolidate them a bit:
from...
to...
Committed and pushed to 8.x. Thanks!
This needs a change notice.
Comment #18
berdirImproved and extended http://drupal.org/node/1642962 so that it also covers this change.
Comment #19
aspilicious commentedGreat!
Comment #20
dave reidHOWEVER, user_label() eventually invokes drupal_alter('user_format_name') which is typically used by Realname module. When performing token replacement, we would want to know which langcode the username is being used as since we could provide the langcode for tokens. There *is* an actual valid use case for this.
Comment #21
berdirHm, there is actually even a much more obvious use case here: t('Anonymous').
Comment #22
dave reidYep, that's the more obvious one too.
Comment #23
gábor hojtsyDone, moving off sprint.
Comment #25
webchickThis change has caused XSS by default in D7 templates being ported to D8. See #1811684: XSS: Bartik's node.tpl.php prone to XSS (prints $title).
Comment #26
gábor hojtsySo now let's remove this :D #2142979: Entity label langcode argument is a lie, incompatible with current API.