Projet

Général

Profil

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

root / drupal7 / sites / all / modules / ctools / plugins / arguments / user_name.inc @ e4c061ad

1
<?php
2

    
3
/**
4
 * @file
5
 *
6
 * Plugin to provide an argument handler for a username
7
 */
8

    
9
/**
10
 * Plugins are described by creating a $plugin array which will be used
11
 * by the system that includes this file.
12
 */
13
$plugin = array(
14
  'title' => t("User: name"),
15
  // keyword to use for %substitution
16
  'keyword' => 'user',
17
  'description' => t('Creates a user context from a user name.'),
18
  'context' => 'ctools_argument_user_name_context',
19
  'placeholder form' => array(
20
    '#type' => 'textfield',
21
    '#description' => t('Enter the username of a user for this argument'),
22
  ),
23
);
24

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

    
34
  // We can accept either a node object or a pure nid.
35
  if (is_object($arg)) {
36
    return ctools_context_create('user', $arg);
37
  }
38

    
39
  $account = user_load_by_name($arg);
40
  if (!$account) {
41
    return NULL;
42
  }
43
  return ctools_context_create('user', $account);
44
}
45

    
46

    
47