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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

onedotover’s picture

Component: Core integration » Entity CRUD controller
Issue summary: View changes
Status: Active » Needs review
FileSize
5.46 KB

Status: Needs review » Needs work

The last submitted patch, 1: entity-identifier_fix-2200771.patch, failed testing.

onedotover’s picture

FileSize
3.35 KB
onedotover’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 3: entity-identifier_fix-2200771-3.patch, failed testing.

onedotover’s picture

Status: Needs work » Needs review
FileSize
2.22 KB
Chris Matthews’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

The 5 year old patch in #6 does not apply to the latest entity 7.x-1.x-dev and (if still relevant) needs reroll.

Checking patch includes/entity.inc...
error: while searching for:
   * @see entity_delete()
   */
  public function delete() {
    $id = $this->identifier();
    if (isset($id)) {
      entity_get_controller($this->entityType)->delete(array($id));
    }

error: patch failed: includes/entity.inc:203
error: includes/entity.inc: patch does not apply
Checking patch includes/entity.ui.inc...
shubham.prakash’s picture

Status: Needs work » Needs review
FileSize
2.24 KB

Patch for the same.

rpayanm’s picture

Issue tags: -Needs reroll