Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Entity:identifier() and entity_id() are used throughout the entity module to gather the ID representing the entity. However, these functions actually return the name of the entity if it is defined. What really needs to be used in these scenarios is Entity:internalIdentifier(). An example of this is the Entity:delete() function:
public function delete() {
$id = $this->identifier(); // << This is not an id, it is a name property
if (isset($id)) {
entity_get_controller($this->entityType)->delete(array($id));
}
}
This should be using the internalIdentifier() as follows:
public function delete() {
$id = $this->internalIdentifier();
if (isset($id)) {
entity_get_controller($this->entityType)->delete(array($id));
}
}
Anywhere entity_id(), Entity:identifier() and Entity:internalIdentifier() are called in the module need attention. A patch has been uploaded with recommended changes.
Comment | File | Size | Author |
---|---|---|---|
#8 | 2200771-8.patch | 2.24 KB | shubham.prakash |
| |||
#6 | entity-identifier_fix-2200771-6.patch | 2.22 KB | onedotover |
Comments
Comment #1
onedotover CreditAttribution: onedotover commentedComment #3
onedotover CreditAttribution: onedotover commentedComment #4
onedotover CreditAttribution: onedotover commentedComment #6
onedotover CreditAttribution: onedotover commentedComment #7
Chris Matthews CreditAttribution: Chris Matthews as a volunteer commentedThe 5 year old patch in #6 does not apply to the latest entity 7.x-1.x-dev and (if still relevant) needs reroll.
Comment #8
shubham.prakash CreditAttribution: shubham.prakash at OpenSense Labs commentedPatch for the same.
Comment #9
rpayanm