Removing translation directories
[project/ctools.git] / views_content / plugins / relationships / user_from_view.inc
1 <?php
2
3 /**
4 * @file
5 * Plugin to provide an relationship handler for user from term.
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('User from view'),
14 'keyword' => 'user',
15 'description' => t('Extract a user context from a view context of the base type user.'),
16 'required context' => new ctools_context_required(t('View'), 'view', array('base' => 'users')),
17 'context' => 'views_content_user_from_view_context',
18 'settings form' => 'views_content_user_from_view_settings_form',
19 'settings form validate' => 'views_content_user_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_user_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('user', 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 if (isset($view->result[$row])) {
37 $uid = $view->result[$row]->{$view->base_field};
38 if ($uid) {
39 $user = user_load($uid);
40 return ctools_context_create('user', $user);
41 }
42 }
43 return ctools_context_create_empty('user', NULL);
44 }
45
46 /**
47 * Settings form for the relationship.
48 */
49 function views_content_user_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_user_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 }