You are here

function og_create_field in Organic groups 7

Same name and namespace in other branches
  1. 7.2 og.module \og_create_field()

Create an organic groups field in a bundle.

Parameters

$field_name: The field name

$entity_type: The entity type

$bundle: The bundle name.

28 calls to og_create_field()
generate-og-d7-content-update-7001.php in scripts/generate-og-d7-content-update-7001.php
OgAccessTestCase::testOgAccess in og_access/og_access.test
Group with access field .
OgAccessTestCase::testOgContentAccessDefault in og_access/og_access.test
Group with access field and group content with default definition.
OgAccessTestCase::testOgContentAccessNotDefault in og_access/og_access.test
Group with access field and group content with different definition from the group.
OgAccessTestCase::testOgStrictPrivate in og_access/og_access.test
Test "Strict private" variable enabled or disabled.

... See full list

File

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

Code

function og_create_field($field_name, $entity_type, $bundle) {

  // Don't allow creating a group field on a group entity type.
  if ($entity_type == 'group' && $field_name == OG_GROUP_FIELD) {
    throw new Exception('Cannot add group field to a group entity.');
  }
  if ($group_field = og_fields_info($field_name)) {
    $field = field_info_field($field_name);
    if (empty($field)) {
      $field = field_create_field($group_field['field']);
    }
    $instance = field_info_instance($entity_type, $field_name, $bundle);
    if (empty($instance)) {
      $instance = $group_field['instance'];
      $instance += array(
        'field_name' => $field_name,
        'bundle' => $bundle,
        'entity_type' => $entity_type,
      );
      field_create_instance($instance);
    }
  }
}