You are here

function og_entity_property_info in Organic groups 7.2

Same name and namespace in other branches
  1. 7 og.module \og_entity_property_info()

Implements hook_entity_property_info().

File

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

Code

function og_entity_property_info() {
  $info = array();

  // Add OG membership metadata for every bundle that is a group content.
  foreach (og_get_all_group_content_bundle() as $entity_type => $bundles) {
    foreach ($bundles as $bundle => $bundle_value) {
      $info[$entity_type]['bundles'][$bundle]['properties']['og_membership'] = array(
        'label' => t("OG memberships"),
        'type' => 'list<og_membership>',
        'description' => t("A list of all OG memberships of the @name entity.", array(
          '@name' => $entity_type,
        )),
        'getter callback' => 'og_get_og_membership_properties',
      );

      // Add per-state properties.
      $general = $info[$entity_type]['bundles'][$bundle]['properties']['og_membership'];
      foreach (og_group_content_states() as $state => $state_label) {
        $params = array(
          '@state' => $state_label,
          '@name' => $entity_type,
        );
        $info[$entity_type]['bundles'][$bundle]['properties']['og_membership__' . $state] = $general;
        $info[$entity_type]['bundles'][$bundle]['properties']['og_membership__' . $state]['label'] = t('@state OG membership', $params);
        $info[$entity_type]['bundles'][$bundle]['properties']['og_membership__' . $state]['description'] = t("A list of all OG memberships of the @name entity with @state state.", $params);
      }

      // Add OG membership per field in a bundle.
      foreach (og_get_group_audience_fields($entity_type, $bundle) as $field_name => $label) {
        $params = array(
          '@label' => $label,
        );
        $field_info = field_info_field($field_name);
        $group_type = $field_info['settings']['target_type'];
        $info[$entity_type]['bundles'][$bundle]['properties'][$field_name . '__og_membership'] = array(
          'label' => t('OG membership from field @label', $params),
          'type' => 'list<og_membership>',
          // The bundle in this context means the OG membership type.
          'bundle' => $field_info['settings']['handler_settings']['membership_type'],
          'description' => t('A list of all OG memberships registered in field @label.', $params),
          'getter callback' => 'og_get_field_og_membership_properties',
        );

        // Add per-state properties.
        $general = $info[$entity_type]['bundles'][$bundle]['properties'][$field_name . '__og_membership'];
        foreach (og_group_content_states() as $state => $state_label) {
          $params = array(
            '@label' => $label,
            '@label' => $label,
            '@state' => $state_label,
          );
          $info[$entity_type]['bundles'][$bundle]['properties'][$field_name . '__og_membership__' . $state] = $general;
          $info[$entity_type]['bundles'][$bundle]['properties'][$field_name . '__og_membership__' . $state]['label'] = t('@state OG memberships from field @label', $params);
          $info[$entity_type]['bundles'][$bundle]['properties'][$field_name . '__og_membership__' . $state]['description'] = t('A list of all OG memberships with @state registered in field @label.', $params);
        }
      }
    }
  }
  foreach (og_get_all_group_bundle() as $entity_type => $bundles) {
    foreach ($bundles as $bundle => $bundle_value) {
      $info[$entity_type]['bundles'][$bundle]['properties']['members'] = array(
        'label' => t("Group members"),
        'type' => 'list<user>',
        'description' => t("A list group members of the @name entity.", array(
          '@name' => $entity_type,
        )),
        'getter callback' => 'og_get_group_members_properties',
      );

      // Add per-state properties.
      $general = $info[$entity_type]['bundles'][$bundle]['properties']['members'];
      foreach (og_group_content_states() as $state => $state_label) {
        $params = array(
          '@state' => $state_label,
          '@name' => $entity_type,
        );
        $info[$entity_type]['bundles'][$bundle]['properties']['members__' . $state] = $general;
        $info[$entity_type]['bundles'][$bundle]['properties']['members__' . $state]['label'] = t('@state group members', $params);
        $info[$entity_type]['bundles'][$bundle]['properties']['members__' . $state]['description'] = t("A list of all users of the @name entity with @state state.", $params);
      }
    }
  }
  return $info;
}