You are here

function og_check_field_cardinality in Organic groups 7.2

Return TRUE if a field can be used and has not reached maximum values.

Parameters

$entity_type: The entity type.

$entity: The entity object or entity ID.

$field_name: The group audience field name.

4 calls to og_check_field_cardinality()
OgMembership::save in includes/og.membership.inc
Override Entity::save().
og_get_best_group_audience_field in ./og.module
Get the first best matching group-audience field.
og_ui_add_users_validate in og_ui/og_ui.admin.inc
Validate handler; Add users to group.
og_ui_field_formatter_view in og_ui/og_ui.module
Implements hook_field_formatter_view().

File

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

Code

function og_check_field_cardinality($entity_type, $entity, $field_name) {
  $field = field_info_field($field_name);
  if ($field['cardinality'] == FIELD_CARDINALITY_UNLIMITED) {
    return TRUE;
  }
  $wrapper = entity_metadata_wrapper($entity_type, $entity);
  return count($wrapper->{$field_name . '__og_membership'}
    ->value(array(
    'identifier' => TRUE,
  ))) < $field['cardinality'];
}