function lingotek_get_fc_parent in Lingotek Translation 7.4
Same name and namespace in other branches
- 7.7 lingotek.module \lingotek_get_fc_parent()
- 7.5 lingotek.module \lingotek_get_fc_parent()
- 7.6 lingotek.module \lingotek_get_fc_parent()
1 call to lingotek_get_fc_parent()
File
- ./
lingotek.module, line 1681
Code
function lingotek_get_fc_parent($entity) {
$query = new EntityFieldQuery();
$query
->fieldCondition($entity
->fieldInfo(), 'revision_id', $entity->revision_id);
if (!$entity
->isInUse()) {
$query
->age(FIELD_LOAD_REVISION);
}
$result = $query
->execute();
$num_results = isset($result) ? sizeof($result) : 0;
if (!isset($result) || $num_results != 1) {
// found more or less than we bargained for. Abort.
LingotekLog::error('Found @parents parents when querying for field-collection parent: @entity', array(
'@parents' => $num_results,
'@entity' => print_r($entity, TRUE),
));
return NULL;
}
foreach ($result as $parent_type => $parents) {
if (!isset($result) || sizeof($result) != 1) {
LingotekLog::error('Found @parents parents when querying for field-collection parent: @entity', array(
'@parents' => $num_results,
'@entity' => print_r($entity, TRUE),
));
return NULL;
}
foreach (array_keys($parents) as $parent_id) {
return entity_load_single($parent_type, $parent_id);
}
}
}