first commit
[step2_drupal.git] / content_profile / content_profile.panels.inc
blob2291f01676c11899263fc2812494ef7b22573046
1 <?php
2 // $Id: content_profile.panels.inc,v 1.1.2.1 2009/01/04 12:02:19 fago Exp $
4 /**
5  * @file
6  * Panels integration
7  */
9 /**
10  * Plugin to provide an relationship handler for node from user
11  */
12 function content_profile_panels_relationships() {
13   $args['node_from_user'] = array(
14     'title' => t("Profile Node from user"),
15     'keyword' => 'content_profile',
16     'description' => t('Adds a Content Profile from user context'),
17     'required context' => new panels_required_context(t('User'), 'user'),
18     'context' => 'content_profile_panels_context',
19     'settings form' => 'content_profile_panels_settings_form',
20     'settings form validate' => 'content_profile_panels_settings_form_validate',
21   );
22   return $args;
25 /**
26  * Return a new context based on an existing context
27  */
28 function content_profile_panels_context($context = NULL, $conf) {
29   // If unset it wants a generic, unfilled context, which is just NULL
30   if (empty($context->data)) {
31     return panels_context_create_empty('node', NULL);
32   }
34   if (isset($context->data->uid)) {
35     // Load the node for the requested type
36     $uid = $context->data->uid;
37     $content_profile_node = content_profile_load($conf['type'], $uid);
39     // Send it to panels
40     return panels_context_create('node', $content_profile_node);
41   }
42   else {
43     return panels_context_create_empty('node', NULL);
44   }
47 /**
48  * Settings form for the relationship
49  */
50 function content_profile_panels_settings_form($conf) {
51   $options = content_profile_get_types('names');
52   $form['type'] = array(
53     '#type' => 'select',
54     '#title' => t('Relationship type'),
55     '#options' => $options,
56     '#default_value' => $conf['type']
57   );
59   return $form;