Projet

Général

Profil

Paste
Télécharger (1,03 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / ctools / plugins / relationships / user_from_node.inc @ 6e3ce7c2

1
<?php
2

    
3
/**
4
 * @file
5
 * Plugin to provide an relationship handler for node from user.
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 author'),
14
  'keyword' => 'user',
15
  'description' => t('Creates the author of a node as a user context.'),
16
  'required context' => new ctools_context_required(t('Node'), 'node'),
17
  'context' => 'ctools_user_from_node_context',
18
  'no ui' => TRUE,
19
);
20

    
21
/**
22
 * Return a new context based on an existing context.
23
 */
24
function ctools_user_from_node_context($context, $conf) {
25
  // If unset it wants a generic, unfilled context, which is just NULL.
26
  if (empty($context->data) || !isset($context->data->uid)) {
27
    return ctools_context_create_empty('user', NULL);
28
  }
29

    
30
  if (isset($context->data->uid)) {
31
    // Load the user that is the author of the node.
32
    $uid = $context->data->uid;
33
    $account = user_load($uid);
34

    
35
    // Send it to ctools.
36
    return ctools_context_create('user', $account);
37
  }
38
}