diff -u b/serial.inc b/serial.inc --- b/serial.inc +++ b/serial.inc @@ -197,10 +197,10 @@ $results = $query->execute(); if (!empty($results[$entity_type])) { - $entity_info = entity_get_info($entity_type); - foreach ($results[$entity_type] as $entity) { - $entity = entity_load_unchanged($entity_type, $entity->{$entity_info['entity keys']['id']}); + list($id, , $bundle) = entity_extract_ids($entity_type, $entity); + + $entity = entity_load_unchanged($entity_type, $id); $entity->{$field_name} = array( LANGUAGE_NONE => array( array( diff -u b/serial.module b/serial.module --- b/serial.module +++ b/serial.module @@ -194,14 +194,14 @@ * Replace token for generic entity type. */ function serial_tokens($type, array $tokens, array $data = array(), array $options = array()) { - $replacements = array(); $entity_info = entity_get_info($type); + $replacements = array(); if (empty($entity_info) || empty($data[$type])) { return $replacements; } - $entity = $data[$type]; + list(, , $bundle) = entity_extract_ids($type, $data[$type]); $pathauto = module_exists('pathauto'); foreach ($tokens as $name => $original) { @@ -213,18 +213,14 @@ continue; } - if ($pathauto) { - $pattern = pathauto_pattern_load_by_entity($type, $entity->{$entity_info['bundle keys']['bundle']}); - - if (strpos($pattern, "$type:$field_name") !== FALSE) { - continue; - } + if ($pathauto && strpos(pathauto_pattern_load_by_entity($type, $bundle), "$type:$field_name") !== FALSE) { + continue; } /* @var array $items */ - $items = field_get_items($type, $entity, $field_name); + $items = field_get_items($type, $data[$type], $field_name); - if (FALSE !== $items) { + if (empty($items)) { continue; }