Skip to content

Instantly share code, notes, and snippets.

@madeingnecca
Last active December 15, 2015 00:18
Show Gist options
  • Save madeingnecca/5171501 to your computer and use it in GitHub Desktop.
Save madeingnecca/5171501 to your computer and use it in GitHub Desktop.
DRUPAL 7 - get ID from entity
<?php
// Method 1: get both id key and id value. Verbose way.
$entity_wrapper = entity_metadata_wrapper($entity_type, $entity);
$pri = $entity_wrapper->entityKey('id');
$entity_id = $entity_wrapper->$pri->value();
// Method 2: get only id value. More succint way.
list($entity_id) = entity_extract_ids($entity_type, $entity);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment