Skip to content

Instantly share code, notes, and snippets.

@baisong
Created September 11, 2012 19:55
Show Gist options
  • Select an option

  • Save baisong/3701570 to your computer and use it in GitHub Desktop.

Select an option

Save baisong/3701570 to your computer and use it in GitHub Desktop.
attempt to create EntityFieldQuery accounting for vsite
<?php
/**
* Returns a new EntityFieldQuery in the current space, if vsite is enabled.
*/
function _os_node_query($type = '') {
// Prepares a new EntityFieldQuery for nodes.
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node');
// Adds node type condition if given
if (isset($type) && strlen($type) > 0) {
dpm($type);
$query->entityCondition('bundle', $type);
}
$query->propertyCondition('status', 1);
// Returns if we are running a single-tenant installation.
if (!module_exists('vsite')) {
return $query;
}
// Returns if we cannot load the current space.
$space = spaces_get_space();
if (!is_numeric($space->id)) {
return $query;
}
// Adds field condition for OG audience if available.
$query->fieldCondition(OG_AUDIENCE_FIELD, 'target_id', $space->id);
return $query;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment