entity_label() exploits entity keys to return the entity label unless a 'label callback' is defined. Atm the label callback is called without passing along the [entity] $type parameter, thus making impossible implementing a callback generalizing entity label handling (see http://drupal.org/project/title).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

plach’s picture

Status: Active » Needs review
Issue tags: +API addition
FileSize
619 bytes

Status: Needs review » Needs work

The last submitted patch, entity_label-1096446-1.patch, failed testing.

plach’s picture

Title: entity_label() is not passing along the $type parameter » entity_label() is not passing along the $entity_type parameter
Status: Needs work » Needs review
FileSize
2.71 KB

It was $entity_type instead of $type (we should uniform this elsewhere).

The attached patch updates the documentation accordingly.

Tor Arne Thune’s picture

Version: 7.x-dev » 8.x-dev
Issue tags: +Needs backport to D7

Subscribing

tstoeckler’s picture

Code looks good, haven't tried it out, though.
Elsewhere we use foo($entity_type, $entity) instead of foo($entity, $entity_type). It makes sense to do this here, for backwards compatibility with D7, but since this is marked against 8.x, it does seem a bit weird.

plach’s picture

Agreed.

Rerolled the patch for D7 and changed the argument order in the D8 one.

tstoeckler’s picture

I just looked through all core invocations of hook_entity_info() and found field_test_entity_label_callback. The tests should not pass because of that. I don't really know why that test is in the Field scope not in the Entity scope, but I guess that's not for this issue.

plach’s picture

Oops, here is a D8 version taking care of tests.

tstoeckler’s picture

Status: Needs review » Reviewed & tested by the community

Awesome. This is RTBC.
After committing to D8, http://drupal.org/files/issues/entity_label-1096446-6.D7.patch is RTBC against D7.

Dries’s picture

Version: 8.x-dev » 7.x-dev

Committed to 8.x.

Moving to 7.x for webchick to consider as this is a (small) API change.

plach’s picture

@Dries:

Thanks :)

@webchick:

As pointed out in #5 the API change is backward compatible, so it should be a harmless change.

plach’s picture

Here is the D7 RTBC patch from #6 for the bot.

tstoeckler’s picture

Since http://drupal.org/project/title needs this (among probably others in the future), it's not only a "nice-cleanup" kind of thing, but actually quite needed for getting something like Title in D8 core.

Patch is still RTBC.

andypost’s picture

Status: Reviewed & tested by the community » Needs work

Suppose D8 should have the same argument order or we stuck with contrib update|upgrade

+++ b/includes/common.incundefined
@@ -7583,7 +7583,7 @@ function entity_label($entity_type, $entity) {
-    $label = $info['label callback']($entity);
+    $label = $info['label callback']($entity, $entity_type);

D7 version is not forware compatible with D8? Any reason has different signatures?

+++ b/includes/common.incundefined
@@ -7584,7 +7584,7 @@ function entity_label($entity_type, $entity) {
-    $label = $info['label callback']($entity);
+    $label = $info['label callback']($entity_type, $entity);

D8 version been commited is different arguments order from D7

Powered by Dreditor.

plach’s picture

Status: Needs work » Reviewed & tested by the community

@andypost:

D8 version been commited is different arguments order from D7

As explained in #12 this is a design choice to preserve backward compatibility: there might be contrib/custom code around implementing a label callback and adding a parameter in first position would break it whereas appending one would not.

Suppose D8 should have the same argument order or we stuck with contrib update|upgrade

This (already) is nothing more than an API change between D7 and D8, we will see gazillions of them I guess.

tstoeckler’s picture

Issue tags: -Needs backport to D7

Removing backport tag now.

webchick’s picture

I'm confused. Does this need backport to D7 or not? If so, why was the tag removed?

Tor Arne Thune’s picture

Issue tags: +Needs backport to D7

Yes

tstoeckler’s picture

Oh sorry, I thought the tag was to be used for D8 issues that should be assigned to D7 after commit, that's why I removed it. Yes it should be applied to D7.

sun’s picture

Can we get this in, please? The backported patch seems to be RTBC for D7.

catch’s picture

Issue tags: +Needs documentation

I don't see any update documentation added here, is it needed? Adding tag anyway.

plach’s picture

What do you mean? The second hunk is all about updating the documentation...

catch’s picture

Sorry I meant http://drupal.org/update/modules/6/7

There's not a 7/8 page yet (and there is the issue to make API changes node types), but this looks like it could use a mention.

tstoeckler’s picture

Issue tags: -Needs documentation

I added a 7.x to 8.x update docs page: http://drupal.org/node/1152742
And added this as the first item.
That would probably need to be updated if the D7 patch got in.

plach’s picture

Issue tags: +translatable fields
webchick’s picture

#12: entity_label-1096446-6.patch queued for re-testing.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

This seems like it should be pretty harmless. If not, there's always another week or so to test.

Committed to 7.x. Thanks!

tstoeckler’s picture

Updated the module update documentation: http://drupal.org/node/1152742#label-callback-params

Status: Fixed » Closed (fixed)
Issue tags: -translatable fields, -API addition, -Needs backport to D7

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