You are here

function og_get_field_og_membership_properties in Organic groups 7.2

Property getter callback for OG membership per field.

See also

og_entity_property_info()

2 string references to 'og_get_field_og_membership_properties'
og_entity_property_info in ./og.module
Implements hook_entity_property_info().
og_invalidate_cache in ./og.module
Invalidate cache.

File

./og.module, line 352
Enable users to create and manage groups with roles and permissions.

Code

function og_get_field_og_membership_properties($entity, array $options, $name, $type) {
  $args = explode('__', $name);

  // Field name might have double underscore as-well, so we need to make
  // sure we get it right.
  $last_char = substr($name, -1);
  $state = is_numeric($last_char) ? $last_char : FALSE;

  // The number of characters to ignore in the name (i.e. remove the
  // "__og_membership" or "__og_membership__0").
  $remove_char = $state ? -18 : -15;
  $field_name = substr($name, 0, $remove_char);
  $field_name = $args[0];
  $field = field_info_field($field_name);
  $states = count($args) == 2 ? FALSE : array(
    $args[2],
  );
  $result = og_get_entity_groups($type, $entity, $states, $field_name);
  $target_type = $field['settings']['target_type'];
  return !empty($result[$target_type]) ? array_keys($result[$target_type]) : array();
}