'entity keys' => array(
        'id' => 'order_id',
        'label' => t('Order'),
      ),

should be

      'entity keys' => array(
        'id' => 'order_id',
        'label' => 'order_id',
      ),

Because of this calls to entity_label() return FALSE.

Comments

anrikun created an issue. See original summary.

anrikun’s picture

Issue summary: View changes
anrikun’s picture

Sorry, this has changed since #2788513: uc_order entity keys are WRONG.
Anyway 'label' should be set for entity_label() to function correctly.

TR’s picture

Title: Wrong entity keys declaration for uc_order label » Add 'label' to uc_order entity keys declaration
Category: Bug report » Feature request

https://api.drupal.org/api/drupal/modules%21system%21system.api.php/func...

The documentation for hook_entity_info() says that 'entity keys' is optional, and indeed the example implementation shown on that page (taken from system.api.php) does NOT show a 'label' key under 'entity keys'.

Also according to this documentation, entity_label() is only supposed to be used to get the value returned by the 'label callback'.

Note that entity_label() checks to see if the ['entity keys']['label'] element is set before using it. So it doesn't generate an error, it just doesn't do the right thing.

If there's a bug here then it's that entity_label() doesn't return the declared entity 'label' (which is a *mandatory* field in hook_entity_info()) when there is no 'label callback'. That's totally wrong behaviour if entity_label() is meant to return the entity label in all cases, not just return the result of the 'label callback' function. But entity_label() was not written to return the entity label - it returns FALSE because there is no 'label callback' - that's what it was meant to do.

The whole 'label callback' mess is something that should have been removed from Drupal years ago because it's legacy code and does the wrong thing, especially in D8. See #2450793: Properly deprecate support for entity type label callbacks

So, I would strongly suggest using entity_label() only for its intended purpose. Or if this usage is in someone else's code, encourage them to use it only to get the value returned by the 'label callback'.

If you want to change this in Ubercart, give me a suggestion - order_id is NOT a good choice for a label. And I will not put a 'label callback' into Ubercart - that does not belong anywhere in Drupal.