Projet

Général

Profil

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

root / drupal7 / sites / all / modules / ctools / plugins / arguments / uid.inc @ c304a780

1
<?php
2

    
3
/**
4
 * @file
5
 * Plugin to provide an argument handler for a user id.
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: ID"),
14
  // Keyword to use for %substitution.
15
  'keyword' => 'user',
16
  'description' => t('Creates a user context from a user ID argument.'),
17
  'context' => 'ctools_argument_uid_context',
18
  'placeholder form' => array(
19
    '#type' => 'textfield',
20
    '#description' => t('Enter the user ID of a user for this argument'),
21
  ),
22
  'default' => array('to_arg' => TRUE),
23
// This is in pagemanager.
24
  'path placeholder' => '%pm_uid_arg',
25
  'path placeholder to_arg' => TRUE,
26
  'no ui' => TRUE,
27
);
28

    
29
/**
30
 * Discover if this argument gives us the user we crave.
31
 */
32
function ctools_argument_uid_context($arg = NULL, $conf = NULL, $empty = FALSE) {
33
  // If unset it wants a generic, unfilled context.
34
  if ($empty) {
35
    return ctools_context_create_empty('user');
36
  }
37

    
38
  // We can accept either a node object or a pure nid.
39
  if (is_object($arg)) {
40
    return ctools_context_create('user', $arg);
41
  }
42

    
43
  if (!is_numeric($arg)) {
44
    return NULL;
45
  }
46

    
47
  $account = user_load($arg);
48
  if (!$account) {
49
    return NULL;
50
  }
51

    
52
  return ctools_context_create('user', $account);
53
}