Closed (works as designed)
Project:
Drupal core
Version:
8.0.x-dev
Component:
entity system
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
24 Oct 2012 at 18:25 UTC
Updated:
29 Jul 2014 at 21:23 UTC
$entity_info['entity keys']['id'] & Co are duplicating MyEntity::id() & Co method overrides.::$id property (e.g., 'nid', 'name', etc), you have to
'entity keys' => array(
'id' => 'name',
'label' => 'label',
'uuid' => 'uuid',
),
/**
* Overrides Drupal\Core\Entity\Entity::id().
*/
public function id() {
return $this->name;
}
Comments
Comment #1
sunI now see that DatabaseStorageController uses the entity info like this:
So those use-cases cannot work with an ::id() method, because there is no entity object yet.
However. The entity class is known.
And how the keys are used/implemented on the entity class is actually specific to a particular entity class. I.e., if you override the entity class, then the entity keys definition in entity info may no longer be valid.
Thus, the entity keys definition is actually bound to a specific class implementation.
I wonder whether we could do this:
Or possibly also this:
Or perhaps even this?
Comment #2
berdirThe explicit id() overrides exist for performance reasons. In the issue where we removed $this->entityInfo from the entity classes, it was decided that we do this.
The plan for entity id's is to standardize on id (and e.g. use user_id when referencing a user). All entities which follow that convention won't need to override id().
There is no way to mandate/document static properties/methods using EntityInterface, so I'm not sure if that's a good idea or not.
Comment #3
tim.plunkettI think with the move to annotations, this has become less confusing. And the performance gain is important.