function og_views_data_alter in Organic groups 7
Same name and namespace in other branches
- 8 og.views.inc \og_views_data_alter()
- 7.2 includes/views/og.views.inc \og_views_data_alter()
Implements hook_views_data_alter().
File
- includes/
og.views.inc, line 141 - Provides support for the Views module.
Code
function og_views_data_alter(&$data) {
$group_entities = og_get_all_group_entity();
$group_content_entities = og_get_all_group_content_entity();
foreach (entity_get_info() as $entity_type => $info) {
if (!empty($info['fieldable'])) {
if (!empty($group_entities[$entity_type])) {
// OG group relationship.
$data[$info['base table']]['og_rel'] = array(
'group' => t('OG group'),
'title' => t('OG group from @entity', array(
'@entity' => ucfirst($info['label']),
)),
'help' => t('The OG group associated with the @entity entity.', array(
'@entity' => ucfirst($info['label']),
)),
'relationship' => array(
// Pass the entity to the handler.
'entity' => $entity_type,
'handler' => 'og_handler_relationship',
'label' => t('@entity being the OG group', array(
'@entity' => $entity_type,
)),
'base' => 'og',
'base field' => 'etid',
'relationship field' => $info['entity keys']['id'],
),
);
// OG group's related entity.
$data['og']['og_related_' . $entity_type] = array(
'group' => t('OG group'),
'title' => t('@entity from OG group', array(
'@entity' => ucfirst($info['label']),
)),
'help' => t('The @entity entity that is associated with the OG group.', array(
'@entity' => $info['label'],
)),
'relationship' => array(
'handler' => 'views_handler_relationship',
'label' => t('@entity from OG group', array(
'@entity' => $entity_type,
)),
'base' => $info['base table'],
'base field' => $info['entity keys']['id'],
'relationship field' => 'etid',
),
);
}
if (!empty($group_content_entities[$entity_type])) {
// OG membership relationship.
$data[$info['base table']]['og_membership_rel'] = array(
'group' => t('OG membership'),
'title' => t('OG membership from @entity', array(
'@entity' => ucfirst($info['label']),
)),
'help' => t('The OG membership associated with the @entity entity.', array(
'@entity' => ucfirst($info['label']),
)),
'relationship' => array(
// Pass the entity to the handler.
'entity' => $entity_type,
'handler' => 'og_handler_relationship',
'label' => t('OG membership from @entity', array(
'@entity' => $entity_type,
)),
'base' => 'og_membership',
'base field' => 'etid',
'relationship field' => $info['entity keys']['id'],
),
);
// OG membership's related entity.
$data['og_membership']['og_membership_related_' . $entity_type] = array(
'group' => t('OG membership'),
'title' => t('@entity from OG membership', array(
'@entity' => ucfirst($info['label']),
)),
'help' => t('The @entity entity that is associated with the OG membership.', array(
'@entity' => $info['label'],
)),
'relationship' => array(
'handler' => 'views_handler_relationship',
'label' => t('@entity from OG membership', array(
'@entity' => $entity_type,
)),
'base' => $info['base table'],
'base field' => $info['entity keys']['id'],
'relationship field' => 'etid',
),
);
}
}
}
// Override group audience - "gid" (group ID) field argument.
$data['og_membership']['group']['argument']['handler'] = 'og_handler_argument_group_audience_gid';
// Override group and group membership - "state" filter and add a field.
foreach (array(
'og',
'og_membership',
) as $type) {
$data[$type]['state']['filter']['handler'] = 'og_handler_filter_group_audience_state';
$data[$type]['state']['field']['handler'] = 'og_handler_field_group_audience_state';
}
// Remove group audience - "state" and "created", as they are deprecated and
// we have this data in the group membership entity.
foreach (array(
'state',
'created',
) as $type) {
unset($data['field_data_group_audience']['group_audience_' . $type]);
}
}