summaryrefslogtreecommitdiffstats
path: root/views/link.views.inc
blob: 4e079b07f82b5b54775af4ee6dc1d906ae825560 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
/**
 * @file
 * Contains functions handling views integration.
 */

/**
 * Implementation of hook_views_handlers().
 */
function link_views_handlers() {
  return array(
    'info' => array(
      'path' => drupal_get_path('module', 'link') .'/views',
    ),
    'handlers' => array(
      'link_views_handler_argument_target' => array(
        'parent' => 'views_handler_argument',
      ),
      'link_views_handler_filter_protocol' => array(
        'parent' => 'views_handler_filter_string',
      ),
    ),
  );
}

/**
 * Return CCK Views data for the link_field_settings($op == 'views data').
 */
function link_views_content_field_data($field) {
  // Build the automatic views data provided for us by CCK.
  // This creates all the information necessary for the "url" field.
  $data = content_views_field_views_data($field);

  $db_info = content_database_info($field);
  $table_alias = content_views_tablename($field);
  $field_types = _content_field_types();

  // Tweak the automatic views data for the link "url" field.
  // Set the filter title to "@label URL"
  $data[$table_alias][$field['field_name'] .'_url']['filter']['title'] = t('@label URL', array('@label' => t($field_types[$field['type']]['label']))) .': '. t($field['widget']['label']);
  // Remove the argument handling for URLs.
  unset($data[$table_alias][$field['field_name'] .'_url']['argument']);

  // Build out additional views data for the link "title" field.
  $data[$table_alias][$field['field_name'] .'_title'] = array(
    'group' => t('Content'),
    'title' => t('@label title', array('@label' => t($field_types[$field['type']]['label']))) .': '. t($field['widget']['label']) .' ('. $field['field_name'] .')',
    'help' =>  $data[$table_alias][$field['field_name'] .'_url']['help'],
    'argument' => array(
      'field' => $db_info['columns']['title']['column'],
      'tablename' => $db_info['table'],
      'handler' => 'content_handler_argument_string',
      'click sortable' => TRUE,
      'name field' => '', // TODO, mimic content.views.inc :)
      'content_field_name' => $field['field_name'],
      'allow_empty' => TRUE,
    ),
    'filter' => array(
      'field' => $db_info['columns']['title']['column'],
      'title' => t('@label title', array('@label' => t($field_types[$field['type']]['label']))),
      'tablename' => $db_info['table'],
      'handler' => 'content_handler_filter_string',
      'additional fields' => array(),
      'content_field_name' => $field['field_name'],
      'allow_empty' => TRUE,
    ),
    'sort' => array(
      'field' => $db_info['columns']['title']['column'],
      'tablename' => $db_info['table'],
      'handler' => 'content_handler_sort',
      'content_field_name' => $field['field_name'],
      'allow_empty' => TRUE,
    ),
  );

  // Build out additional Views filter for the link "protocol" pseudo field.
  // TODO: Add a protocol argument.
  $data[$table_alias][$field['field_name'] .'_protocol'] = array(
    'group' => t('Content'),
    'title' => t('@label protocol', array('@label' => t($field_types[$field['type']]['label']))) .': '. t($field['widget']['label']) .' ('. $field['field_name'] .')',
    'help' =>  $data[$table_alias][$field['field_name'] .'_url']['help'],
    'filter' => array(
      'field' => $db_info['columns']['url']['column'],
      'title' => t('@label protocol', array('@label' => t($field_types[$field['type']]['label']))),
      'tablename' => $db_info['table'],
      'handler' => 'link_views_handler_filter_protocol',
      'additional fields' => array(),
      'content_field_name' => $field['field_name'],
      'allow_empty' => TRUE,
    ),
  );

  // Build out additional Views argument for the link "target" pseudo field.
  // TODO: Add a target filter.
  $data[$table_alias][$field['field_name'] .'_target'] = array(
    'group' => t('Content'),
    'title' => t('@label target', array('@label' => t($field_types[$field['type']]['label']))) .': '. t($field['widget']['label']) .' ('. $field['field_name'] .')',
    'help' =>  $data[$table_alias][$field['field_name'] .'_url']['help'],
    'argument' => array(
      'field' => $db_info['columns']['attributes']['column'],
      'title' => t('@label target', array('@label' => t($field_types[$field['type']]['label']))) .': '. t($field['widget']['label']) .' ('. $field['field_name'] .')',
      'tablename' => $db_info['table'],
      'handler' => 'link_views_handler_argument_target',
      'additional fields' => array(),
      'content_field_name' => $field['field_name'],
      'allow_empty' => TRUE,
    ),
  );

  return $data;
}