1 |
44d2e178
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Definition of views_handler_field_links.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* A abstract handler which provides a collection of links.
|
10 |
|
|
*
|
11 |
|
|
* @ingroup views_field_handlers
|
12 |
|
|
*/
|
13 |
|
|
class views_handler_field_links extends views_handler_field {
|
14 |
|
|
|
15 |
|
|
/**
|
16 |
|
|
* Overrides views_handler_field::option_definition().
|
17 |
|
|
*/
|
18 |
|
|
function option_definition() {
|
19 |
|
|
$options = parent::option_definition();
|
20 |
|
|
|
21 |
|
|
$options['fields'] = array('default' => array());
|
22 |
|
|
$options['check_access'] = array('default' => FALSE);
|
23 |
|
|
$options['destination'] = array('default' => TRUE, 'bool' => TRUE);
|
24 |
|
|
|
25 |
|
|
return $options;
|
26 |
|
|
}
|
27 |
|
|
|
28 |
|
|
/**
|
29 |
|
|
* Overrides views_handler_field::options_form().
|
30 |
|
|
*/
|
31 |
|
|
function options_form(&$form, &$form_state) {
|
32 |
|
|
parent::options_form($form, $form_state);
|
33 |
|
|
|
34 |
|
|
$all_fields = $this->view->display_handler->get_field_labels();
|
35 |
|
|
// Offer to include only those fields that follow this one.
|
36 |
|
|
$field_options = array_slice($all_fields, 0, array_search($this->options['id'], array_keys($all_fields)));
|
37 |
|
|
$form['fields'] = array(
|
38 |
|
|
'#type' => 'checkboxes',
|
39 |
|
|
'#title' => t('Fields'),
|
40 |
|
|
'#description' => t('Fields to be included as links.'),
|
41 |
|
|
'#options' => $field_options,
|
42 |
|
|
'#default_value' => $this->options['fields'],
|
43 |
|
|
'#required' => TRUE,
|
44 |
|
|
);
|
45 |
|
|
|
46 |
|
|
$form['check_access'] = array(
|
47 |
|
|
'#type' => 'checkbox',
|
48 |
|
|
'#title' => t('Evaluate router path for access'),
|
49 |
|
|
'#default_value' => $this->options['check_access'],
|
50 |
|
|
'#description' => t('Will check if the path exists and is accessible for the current user. Might be useful, might be slow.'),
|
51 |
|
|
);
|
52 |
|
|
|
53 |
|
|
$form['destination'] = array(
|
54 |
|
|
'#type' => 'checkbox',
|
55 |
|
|
'#title' => t('Include destination'),
|
56 |
|
|
'#description' => t('Include a "destination" parameter in the link to return the user to the original view upon completing the link action.'),
|
57 |
|
|
'#default_value' => $this->options['destination'],
|
58 |
|
|
);
|
59 |
|
|
}
|
60 |
|
|
|
61 |
|
|
/**
|
62 |
|
|
* Overrides views_handler_field::options_form().
|
63 |
|
|
*/
|
64 |
|
|
function options_submit(&$form, &$form_state) {
|
65 |
|
|
// Remove unselected options.
|
66 |
|
|
$form_state['values']['options']['fields'] = array_filter($form_state['values']['options']['fields']);
|
67 |
|
|
}
|
68 |
|
|
|
69 |
|
|
/**
|
70 |
|
|
* Return the list of links of this field.
|
71 |
|
|
*
|
72 |
|
|
* @return array
|
73 |
|
|
* The links which are used by the render function.
|
74 |
|
|
*/
|
75 |
|
|
function get_links() {
|
76 |
|
|
$links = array();
|
77 |
|
|
foreach ($this->options['fields'] as $field) {
|
78 |
|
|
if (empty($this->view->field[$field]->last_render_text)) {
|
79 |
|
|
continue;
|
80 |
|
|
}
|
81 |
|
|
|
82 |
|
|
$title = $this->view->field[$field]->last_render_text;
|
83 |
|
|
// Use the alter settings for the link field source not this links field.
|
84 |
|
|
$alter = $this->view->field[$field]->options['alter'];
|
85 |
|
|
$url = array('query' => array());
|
86 |
|
|
|
87 |
|
|
// Copy code from views_handler_field::render_as_link().
|
88 |
|
|
$path = $alter['path'];
|
89 |
|
|
if (!empty($path) && $path != '<front>') {
|
90 |
|
|
// Leave path alone on <front> as strip_tags() would remove this.
|
91 |
|
|
// Replace tokens and strip any HTML tags in the path.
|
92 |
|
|
$tokens = $this->get_render_tokens(array());
|
93 |
|
|
$path = strip_tags(decode_entities(strtr($path, $tokens)));
|
94 |
|
|
|
95 |
|
|
if (!empty($alter['path_case']) && $alter['path_case'] != 'none') {
|
96 |
|
|
$path = $this->case_transform($path, $alter['path_case']);
|
97 |
|
|
}
|
98 |
|
|
|
99 |
|
|
if (!empty($alter['replace_spaces'])) {
|
100 |
|
|
$path = str_replace(' ', '-', $path);
|
101 |
|
|
}
|
102 |
|
|
|
103 |
|
|
$url = drupal_parse_url($path);
|
104 |
|
|
if (empty($url)) {
|
105 |
|
|
// Seriously malformed URLs may return FALSE or empty arrays.
|
106 |
|
|
continue;
|
107 |
|
|
}
|
108 |
|
|
$path = $url['path'];
|
109 |
|
|
|
110 |
|
|
// Check router menu item access for the current user.
|
111 |
|
|
if ($this->options['check_access']) {
|
112 |
|
|
$menu_item = menu_get_item($path);
|
113 |
|
|
if (!$menu_item || empty($menu_item['access'])) {
|
114 |
|
|
continue;
|
115 |
|
|
}
|
116 |
|
|
}
|
117 |
|
|
|
118 |
|
|
if (!empty($this->options['destination']) && empty($alter['external'])) {
|
119 |
|
|
// Override any destination argument included in URL.
|
120 |
|
|
$url['query'] = array_merge($url['query'], drupal_get_destination());
|
121 |
|
|
}
|
122 |
|
|
|
123 |
|
|
// Omit tweaks of query, fragment, and link_class.
|
124 |
|
|
|
125 |
|
|
$alt = strtr($alter['alt'], $tokens);
|
126 |
|
|
if ($alt && $alt != $title) {
|
127 |
|
|
// Set the title attribute only if it improves accessibility.
|
128 |
|
|
$url['attributes']['title'] = decode_entities($alt);
|
129 |
|
|
}
|
130 |
|
|
|
131 |
|
|
if (!empty($alter['rel']) && $rel = strtr($alter['rel'], $tokens)) {
|
132 |
|
|
$url['attributes']['rel'] = $rel;
|
133 |
|
|
}
|
134 |
|
|
|
135 |
|
|
$target = check_plain(trim(strtr($alter['target'], $tokens)));
|
136 |
|
|
if (!empty($target)) {
|
137 |
|
|
$url['attributes']['target'] = $target;
|
138 |
|
|
}
|
139 |
|
|
}
|
140 |
|
|
|
141 |
|
|
$links[$field] = array(
|
142 |
|
|
'href' => $path,
|
143 |
|
|
'title' => $title,
|
144 |
|
|
) + $url;
|
145 |
|
|
}
|
146 |
|
|
|
147 |
|
|
return $links;
|
148 |
|
|
}
|
149 |
|
|
|
150 |
|
|
/**
|
151 |
|
|
* Overrides views_handler_field::query().
|
152 |
|
|
*/
|
153 |
|
|
function query() { }
|
154 |
|
|
|
155 |
|
|
} |