public function OgSubspacesSelectionHandler::validateReferencableEntities in Open Atrium Core 7.2
Implements EntityReferenceHandler::validateReferencableEntities().
Overrides EntityReference_SelectionHandler_Generic::validateReferencableEntities
File
- plugins/
entityreference/ selection/ OgSubspacesSelectionHandler.class.php, line 143 - Code for OG Subspaces selection handler
Class
- OgSubspacesSelectionHandler
- OG Subspaces selection handler for OA.
Code
public function validateReferencableEntities(array $ids) {
if (!$ids) {
return $ids;
}
$field_mode = isset($this->instance['field_mode']) ? $this->instance['field_mode'] : 'all';
if ($field_mode == 'default') {
$group_type = $this->field['settings']['target_type'];
$user_groups = oa_core_get_groups_by_user(NULL, $group_type);
if ($this->field['field_name'] == 'oa_parent_space') {
// Let existing parent field be valid.
$parents = oa_core_get_parents($this->entity->nid);
foreach ($parents as $parent) {
$user_groups[$parent] = $parent;
}
}
$result = array_intersect($ids, $user_groups);
return $result;
}
else {
$entity_type = $this->field['settings']['target_type'];
$query = $this
->buildEntityFieldQuery();
$query
->entityCondition('entity_id', $ids, 'IN');
$result = $query
->execute();
if (!empty($result[$entity_type])) {
return array_keys($result[$entity_type]);
}
}
return array();
}