1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Plugin to provide an relationship handler for node from view.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* Plugins are described by creating a $plugin array which will be used
|
10 |
|
|
* by the system that includes this file.
|
11 |
|
|
*/
|
12 |
|
|
$plugin = array(
|
13 |
|
|
'title' => t('Node from view'),
|
14 |
|
|
'keyword' => 'node',
|
15 |
|
|
'description' => t('Extract a node context from a view context of the base type node.'),
|
16 |
|
|
'required context' => new ctools_context_required(t('View'), 'view', array('base' => 'node')),
|
17 |
|
|
'context' => 'views_content_node_from_view_context',
|
18 |
|
|
'edit form' => 'views_content_node_from_view_settings_form',
|
19 |
|
|
'edit form validate' => 'views_content_node_from_view_settings_form_validate',
|
20 |
|
|
'defaults' => array('row' => 1),
|
21 |
|
|
);
|
22 |
|
|
|
23 |
|
|
/**
|
24 |
|
|
* Return a new context based on an existing context.
|
25 |
|
|
*/
|
26 |
|
|
function views_content_node_from_view_context($context, $conf, $placeholder = FALSE) {
|
27 |
|
|
// If unset it wants a generic, unfilled context, which is just NULL.
|
28 |
|
|
if (empty($context->data) || $placeholder) {
|
29 |
|
|
return ctools_context_create_empty('node', NULL);
|
30 |
|
|
}
|
31 |
|
|
$view = views_content_context_get_view($context);
|
32 |
|
|
// Ensure the view executes, but we don't need its output.
|
33 |
|
|
views_content_context_get_output($context);
|
34 |
|
|
|
35 |
|
|
$row = intval($conf['row']) - 1;
|
36 |
c2ac6d1d
|
Assos Assos
|
if (isset($view->result[$row]) && isset($view->base_field) && isset($view->result[$row]->{$view->base_field})) {
|
37 |
85ad3d82
|
Assos Assos
|
$nid = $view->result[$row]->{$view->base_field};
|
38 |
|
|
if ($nid) {
|
39 |
|
|
$node = node_load($nid);
|
40 |
|
|
return ctools_context_create('node', $node);
|
41 |
|
|
}
|
42 |
|
|
}
|
43 |
|
|
return ctools_context_create_empty('node', NULL);
|
44 |
|
|
}
|
45 |
|
|
|
46 |
|
|
/**
|
47 |
|
|
* Settings form for the relationship.
|
48 |
|
|
*/
|
49 |
|
|
function views_content_node_from_view_settings_form($form, &$form_state) {
|
50 |
|
|
$conf = $form_state['conf'];
|
51 |
|
|
$form['row'] = array(
|
52 |
|
|
'#title' => t('Row number'),
|
53 |
|
|
'#type' => 'textfield',
|
54 |
|
|
'#default_value' => $conf['row'],
|
55 |
|
|
);
|
56 |
|
|
|
57 |
|
|
return $form;
|
58 |
|
|
}
|
59 |
|
|
|
60 |
|
|
function views_content_node_from_view_settings_form_validate($form, &$form_state) {
|
61 |
|
|
if (intval($form_state['values']['row']) <= 0) {
|
62 |
|
|
form_error($form['row'], t('Row number must be a positive integer value.'));
|
63 |
|
|
}
|
64 |
|
|
} |