You are here

function flag_views_data_alter in Flag 6

Same name and namespace in other branches
  1. 8.4 flag.views.inc \flag_views_data_alter()
  2. 6.2 includes/flag.views.inc \flag_views_data_alter()
  3. 7.3 includes/views/flag.views.inc \flag_views_data_alter()
  4. 7.2 includes/flag.views.inc \flag_views_data_alter()

Implementation of hook_views_data_alter().

File

includes/flag.views.inc, line 167
Provides support for the Views module.

Code

function flag_views_data_alter(&$data) {
  foreach (array_keys(flag_fetch_definition()) as $flag_type) {
    $flag = flag_flag::factory_by_content_type($flag_type);
    $info = $flag
      ->get_views_info();

    // Add the flag relationship.
    $data[$info['views table']]['flag_content_rel'] = array(
      'group' => t('Flags'),
      'title' => $info['title'],
      'help' => $info['help'],
      'relationship' => array(
        'flag type' => $flag_type,
        'handler' => 'flag_handler_relationship_content',
        'label' => t('flag'),
        'base' => 'flag_content',
        'base field' => 'content_id',
        'relationship field' => $info['join field'],
      ),
    );

    // Add the flag counter relationship.
    $data[$info['views table']]['flag_count_rel'] = array(
      'group' => t('Flags'),
      'title' => $info['counter title'],
      'help' => $info['counter help'],
      'relationship' => array(
        'flag type' => $flag_type,
        'handler' => 'flag_handler_relationship_counts',
        'label' => t('counter'),
        'base' => 'flag_counts',
        'base field' => 'content_id',
        'relationship field' => $info['join field'],
      ),
    );
  }

  // Add a relationship for the user that flagged any type of content.
  $data['users']['flag_user_content_rel'] = array(
    'group' => t('Flags'),
    'title' => t("User's flagged content"),
    'help' => t('Limit results to users that have flagged certain content.'),
    'relationship' => array(
      'base' => 'flag_content',
      'base field' => 'uid',
      'relationship field' => 'uid',
      'handler' => 'flag_handler_relationship_user_content',
      'label' => t('user flagged content'),
    ),
  );
}