1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* Views field handler for rendering node links that point to panelizer tabs.
|
5 |
|
|
*/
|
6 |
|
|
class panelizer_handler_field_link extends views_handler_field_node_link {
|
7 |
|
|
/**
|
8 |
|
|
* Mapping of node paths (the part after node/N) to human-readable labels.
|
9 |
|
|
*
|
10 |
|
|
* This array is used both for the options_form in the select dropdown, and
|
11 |
|
|
* also when rendering the link to define the link text if not overridden.
|
12 |
|
|
*/
|
13 |
|
|
protected $tab_map = array();
|
14 |
|
|
|
15 |
|
|
function construct() {
|
16 |
|
|
parent::construct();
|
17 |
|
|
$this->tab_map = array(
|
18 |
|
|
'settings' => t('Settings'),
|
19 |
|
|
'context' => t('Context'),
|
20 |
|
|
'layout' => t('Layout'),
|
21 |
|
|
'content' => t('Content'),
|
22 |
|
|
);
|
23 |
|
|
}
|
24 |
|
|
|
25 |
|
|
function option_definition() {
|
26 |
|
|
$options = parent::option_definition();
|
27 |
|
|
$options['panelizer_tab'] = array('default' => 'panelizer');
|
28 |
|
|
$options['view_mode'] = array('default' => 'page_manager');
|
29 |
|
|
return $options;
|
30 |
|
|
}
|
31 |
|
|
|
32 |
|
|
function options_form(&$form, &$form_state) {
|
33 |
|
|
parent::options_form($form, $form_state);
|
34 |
|
|
$form['panelizer_tab'] = array(
|
35 |
|
|
'#type' => 'select',
|
36 |
|
|
'#title' => 'Panelizer tab to link to',
|
37 |
|
|
'#options' => $this->tab_map,
|
38 |
|
|
'#default_value' => $this->options['panelizer_tab'],
|
39 |
|
|
);
|
40 |
|
|
|
41 |
|
|
$entity_type = $this->definition['entity_type'];
|
42 |
|
|
$handler = panelizer_entity_plugin_get_handler($entity_type);
|
43 |
|
|
|
44 |
|
|
$view_modes = array();
|
45 |
|
|
foreach ($handler->plugin['view modes'] as $view_mode => $view_mode_info) {
|
46 |
|
|
$view_modes[$view_mode] = $view_mode_info['label'];
|
47 |
|
|
}
|
48 |
|
|
|
49 |
|
|
$form['view_mode'] = array(
|
50 |
|
|
'#type' => 'select',
|
51 |
|
|
'#title' => t('View mode'),
|
52 |
|
|
'#options' => $view_modes,
|
53 |
|
|
);
|
54 |
|
|
}
|
55 |
|
|
|
56 |
|
|
function render_link($entity, $values) {
|
57 |
|
|
if (!$entity) {
|
58 |
|
|
return;
|
59 |
|
|
}
|
60 |
|
|
|
61 |
|
|
$entity_type = $this->definition['entity_type'];
|
62 |
|
|
$handler = panelizer_entity_plugin_get_handler($entity_type);
|
63 |
|
|
|
64 |
|
|
list($entity_id, $revision_id, $bundle) = entity_extract_ids($entity_type, $entity);
|
65 |
|
|
|
66 |
|
|
if ($handler && $handler->is_panelized($bundle) && $handler->panelizer_access($this->options['panelizer_tab'], $entity)) {
|
67 |
|
|
$this->options['alter']['make_link'] = TRUE;
|
68 |
|
|
|
69 |
|
|
$path = str_replace("%$entity_type", $entity_id, $handler->plugin['entity path']) . '/panelizer/' . $this->options['view_mode'] . '/' . $this->options['panelizer_tab'];
|
70 |
|
|
$this->options['alter']['path'] = $path;
|
71 |
|
|
$this->options['alter']['query'] = drupal_get_destination();
|
72 |
|
|
$text = !empty($this->options['text']) ? $this->options['text'] : $this->tab_map[$this->options['panelizer_tab']];
|
73 |
|
|
return $text;
|
74 |
|
|
}
|
75 |
|
|
}
|
76 |
|
|
} |